This post is archived. Some content may be out of date or render incorrectly.
You can use Docker Compose to easily run WordPress in an isolated environment built with Docker containers. This quick-start guide demonstrates how to use Compose to set up and run WordPress. Before starting, you'll need to have Compose installed.
This tutorial has been taken from my latest pull request to the Docker Compose project. The pull request can be found at https://github.com/docker/compose/pull/3275.
The same document should also be available at https://docs.docker.com/compose/wordpress/.
Create an empty project directory.
You can name the directory something easy for you to remember. This directory is the context for your application image. The directory should only contain resources to build that image.
This project directory will contain a docker-compose.yaml
file which will be complete in itself for a good starter wordpress project.
Change directories into your project directory.
For example, if you named your directory my_wordpress
:
$ cd my-wordpress/
Create a docker-compose.yml
file that will start your Wordpress
blog and a separate MySQL
instance with a volume mount for data persistence:
version: '2'services:db:image: mysql:5.7volumes:- "./.data/db:/var/lib/mysql"restart: alwaysenvironment:MYSQL_ROOT_PASSWORD: wordpressMYSQL_DATABASE: wordpressMYSQL_USER: wordpressMYSQL_PASSWORD: wordpresswordpress:depends_on:- dbimage: wordpress:latestlinks:- dbports:- "8000:80"restart: alwaysenvironment:WORDPRESS_DB_HOST: db:3306WORDPRESS_DB_PASSWORD: wordpress
The folder ./.data/db
will be automatically created in the project directory
alongside the docker-compose.yml
which will persist any updates made by wordpress to the
database.
Now, run docker-compose up -d
from your project directory.
This pulls the needed images, and starts the wordpress and database containers, as shown in the example below.
$ docker-compose up -dCreating network "my_wordpress_default" with the default driverPulling db (mysql:5.7)...5.7: Pulling from library/mysqlefd26ecc9548: Pull completea3ed95caeb02: Pull complete...Digest: sha256:34a0aca88e85f2efa5edff1cea77cf5d3147ad93545dbec99cfe705b03c520deStatus: Downloaded newer image for mysql:5.7Pulling wordpress (wordpress:latest)...latest: Pulling from library/wordpressefd26ecc9548: Already existsa3ed95caeb02: Pull complete589a9d9a7c64: Pull complete...Digest: sha256:ed28506ae44d5def89075fd5c01456610cd6c64006addfe5210b8c675881aff6Status: Downloaded newer image for wordpress:latestCreating my_wordpress_db_1Creating my_wordpress_wordpress_1
If you're using Docker Machine, then docker-machine ip MACHINE_VM
gives you the machine address and you can open http://MACHINE_VM_IP:8000
in a browser.
At this point, WordPress should be running on port 8000
of your Docker Host, and you can complete the "famous five-minute installation" as a WordPress administrator.
NOTE: The Wordpress site will not be immediately available on port 8000
because the containers are still being initialized and may take a couple of minutes before the first load.