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.
sudo pacman -S docker-compose
In other distros, you should have the pip
installed to have docker-compose. With pip, try the command below
sudo pip install docker-compose
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.
web:
image: montefuscolo/wordpress
volumes:
- ./:/var/www/html/wp-content/plugins/mapasdevista
environment:
- WORDPRESS_WP_DEBUG=true
links:
- db:mysql
ports:
- "80:80"
db:
image: mariadb
environment:
- MYSQL_USER=thewpuser
- MYSQL_PASSWORD=thewppass
- MYSQL_DATABASE=wordpress
- MYSQL_ROOT_PASSWORD=thesuperpass
web:
anddb:
There are 2 dockers declared, one named web and other named dbimage:
A custom WordPress image[1] is used for web containervolumes:
The local folder is flagged to be mounted inside plugins folder of web containerenvironment:
a variable is declared to turn on debug in WordPresslinks
: db is linked with web, but inside web container the db is called mysqlports
: the port 80 is exposed and published from web to host- 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.
$ docker-compose up
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.
$ docker-compose stop
To start your already created containers, the command is:
$ docker-compose start
To stop and destroy your containers:
$ docker-compose down
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
- https://hub.docker.com/r/montefuscolo/wordpress/~/dockerfile/
- https://github.com/hacklabr/mapasdevista/blob/master/docker-compose.yml
- https://docs.docker.com/compose/reference/