WordPress development with Docker Compose

Last post I told you about how to setup two dockers to run WordPress and MariaDB together. So, in this post I will show thow to use the docker-compose, that is a tool to help you setup run your dockers with one single command.

Installing

In cool distros you should be able to install docker-compose with command below.

In other distros, you should have the pip installed to have docker-compose. With pip, try the command below

Setup

The docker-compose utility rely on a file named docker-compose.yml. This file stores information about how to run one or more docker containers. You can quickly start, stop and remove a set of dockers with docker-compose.

For example, you can have a docker-compose.yml at root of your theme project and with a single command, start a set of dockers to start wordpress and mysql with your plugin already installed in plugins folder. Check the docker-compose.yml below.

  1. web: and db: There are 2 dockers declared, one named web and other named db
  2. image: A custom WordPress image[1] is used for web container
  3. volumes: The local folder is flagged to be mounted inside plugins folder of web container
  4. environment: a variable is declared to turn on debug in WordPress
  5. links: db is linked with web, but inside web container the db is called mysql
  6. ports: the port 80 is exposed and published from web to host
  7. In db container, the official maridb image is used

With this file placed at your theme folder, anyone with docker-compose can quickly setup a environment for test and develop the plugin.

Using

All commands should be run at same folder of docker-compose.yml.

To create and run containers try the command below and point your browser to http://localhost.

To stop containers you can type Ctrl+C at terminal running docker-compose or in another terminal in same folder, you can use the command below.

To start your already created containers, the command is:

To stop and destroy your containers:

Conclusion

Using docker-compose you can run and develop your WordPress stuff right after clone. You don’t need to worry about setup a webserver, database, setup permissions. With docker you can get all running quickly.

References

  1. https://hub.docker.com/r/montefuscolo/wordpress/~/dockerfile/
  2. https://github.com/hacklabr/mapasdevista/blob/master/docker-compose.yml
  3. https://docs.docker.com/compose/reference/