Deploy WordPress through Docker
It's now easier than ever to deploy Wordpress through docker. The tutorial below will allow you to deploy Wordpress, but unlike other tutorials, it will use volumes in order to persist your plugins, themes, and database across containers being destroyed/replaced. Everything is containerized so if you decide to move to another server, all you have to do is copy the files across and run one command. No need to run database dumps or a long list of commands to set permissions.
Steps
Create a folder that everything will go into. When you wish to move to another server, all you will need to do is copy this folder across.
Navigate into that folder you just created.
Copy and paste the following contents into a file called docker-compose.yml
. Make sure to replace [strong root password]
and [wordpress db password]
with some strong randomly generated passwords.
version: '2'
services:
db:
image: mysql:5.7
volumes:
- "./db-data/db:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: [strong root password]
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: [wordpress db password]
wordpress:
depends_on:
- db
image: wordpress:latest
working_dir: /var/www/html
volumes:
- ./wordpress/wp-content/:/var/www/html/wp-content
links:
- db
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: [wordpress db password]
Install docker and docker-compose if you haven't already.
Now simply execute docker-compose up -d
and navigate to your server's IP or hostname in your browser after a minute or two.
References
- Quickstart: Docker Compose and WordPress
- Sitepoint - How to Use the Official Docker WordPress Image
- Wordpress offical Docker repository
First published: 16th August 2018