Docker WordPress setup for local development Mar 2 2018
Development environment will use: WordPress latest - the image uses Apache MariaDB latest
I would like to keep the WordPress files in the host machine so I can tinker with them so we'll be using a mount defined by the environment variable: WPHOME
so let's say we have the following directory schema:
1
2
3
└── wordpress-development
├── WordPress/
└── docker/
inside the docker directory is where the docker-compose.yml (you can see the docker-compose file at the end of the post) file is located, so the command I will run to bring the containers up will look like this for my example:
$ WPHOME=../WordPress/ docker-compose up -d
Here I specifically send the variable WPHOME to point to the WordPress directory on the current parent's directory(../WordPress/) so the WordPress code will be installed there.
For the database I want the data to be persistent but I don't need it to be stored in the host machine so I'll just define a volume so Docker can keep track of it, I named it wpdevmysql so when I do a docker valume ls and I see it I know what that volume represents and is easy to decide if I want to delete it or not, always try to use something descriptive so when you look back at something 6 months from now it still makes sense.
That is it, run:
$ WPHOME=../WordPress/ docker-compose up -d
and now you can go to your browser and do your WordPress installation at http://localhost:8080
enjoy.
Here you can see the docker-compose.yml file (change the passwords just to build the habit of not using default passwords even in your local environment).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
version: '3.1'
services:
mysql:
image: mariadb
restart: always
environment:
- MYSQL_ROOT_PASSWORD=test123
volumes:
- wpdevmysql:/var/lib/mysql
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
- WORDPRESS_DB_PASSWORD=test123
volumes:
- $WPHOME:/var/www/html
volumes:
wpdevmysql: