Using Wordpress with Docker

January 11, 2017

I like wordpress, but it is very intensive to get working, as it uses a lot of PHP and requires SQL. Of course, nowadays you can do everything in Docker, so here is my method for getting wordpress to work great on Docker.

Using Docker, I was able to get 2 blogs run on the smallest DigitalOcean droplet (which was already running two dozen other things). Each blog required 360MB of RAM, and the total Docker space was 3.1G.

The following instructions will enable you to go from zero to Wordpress in about six minutes.


First make a file docker-compose.yml:

version: '2'

     image: mysql:5.7
       - db_data:/var/lib/mysql
     restart: always
       MYSQL_ROOT_PASSWORD: wordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

       - db
     image: wordpress:latest
       - "8001:80"
     restart: always
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_PASSWORD: wordpress
       - /path/to/some/folder/on/your/computer/wp_html:/var/www/html

Then, to start just use (add -d for daemon mode)

docker-compose up

If you need to stop it just use

docker-compose stop

Reverse proxy

If you are using a domain name, you can easily use Caddy as a reverse proxy. Here is an example Caddyfile:

http://blogname {
    proxy / {

Make sure to goto your blog and update it accordingly to http://blogname.

For using SSL, checkout this blog which describes the process for correctly configuring Wordpress to allow it.


Wordpress on docker is also nice because its very easy to move. I basically copied the instructions here to get a simple way to backup and restore a Wordpress instance.

To backup:

docker exec -i wordpress_db_1 mysqldump --user=wordpress --password=wordpress wordpress > backup.sql
tar -czvf wp_html.tar.gz wp_html

To restore:

docker exec -i wordpress_db_1 mysql --user=wordpress --password=wordpress wordpress < backup.sql
tar -xvzf wp_html.tar.gz 

Show comments
Written on 11 January 2017. Categories: coding.

« Skip swiping with adb and bash 
Moderation »