Docker WordPress setup for local development
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:
└── 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).
| |