In this blog post, we will learn how to run multiple WordPress sites in production on a Linux Docker host.
Environment
In my case, I have a CentOS 7.7 Azure VM with Docker installed. The domain name is pointing directly to the VM external IP address.
Setup
The WordPress environment is configured using 4 containers as follow:
- Nginx reverse proxy container – This container allows us to run multiple WordPress instances on a single host.
- Let Encrypt container – This container handles the SSL configuration for my DevOpsRunTime.com domain.
- MySQL container – This is the MySQL database server that runs on a single container
- WordPress container – This is the WordPress container
Notes
To add more WordPress sites, simply add one MySQL container and one WordPress container.
Create Network
The first step will be creating a Docker network that will allow all the containers to communicate.
docker network create dockerwordpressnet
Containers
Below, are the configurations of all the for containers.
Nginx
I will start with deploying Nginx reverse proxy container using the following command.
Note: You can see that the container is using the new network (–net)
docker run --name nginx-proxy --net dockerwordpressnet -p 80:80 -p 443:443 -v ~/certs:/etc/nginx/certs -v /etc/nginx/vhost.d -v /usr/share/nginx/html -v /var/run/docker.sock:/tmp/docker.sock:ro --label com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy -d --restart always jwilder/nginx-proxy
Letsencrypt
The 2nd container will run the letsencrypt container.
docker run --name letsencrypt-nginx-proxy-companion --net dockerwordpressnet -v ~/certs:/etc/nginx/certs:rw -v /var/run/docker.sock:/var/run/docker.sock:ro --volumes-from nginx-proxy -d --restart always jrcs/letsencrypt-nginx-proxy-companion
MySQL
The command below, will deploy the MySQL container.
Note: Each WordPress website will use s dedicated MySQL container, make change the name for each new website.
Please set a strong password for the root account and for the MySQL DB.
docker run --name mysqldb01 --net dockerwordpressnet -v mysqldb01:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=SETROOTPASSWORD -e MYSQL_DATABASE=db1 -e MYSQL_USER=db1user -e MYSQL_PASSWORD=MYQLPASSWORD -d --restart always mysql:5.7
WordPress
The last container will deploy WordPress using the latest WordPress image.
Note: Make sure the username and password for the DB match the values of the MySQL container.
You also need to specify the domain name in the environment values as shown below.
docker run --name devopsruntime --net dockerwordpressnet -v devopsruntime:/var/www/html -v ~/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini -e WORDPRESS_DB_HOST=mysqldb01:3306 -e WORDPRESS_DB_NAME=db1 -e WORDPRESS_DB_USER=db1user -e WORDPRESS_DB_PASSWORD=MYQLPASSWORD -e VIRTUAL_HOST=www.devopsruntime.com -e LETSENCRYPT_HOST=www.devopsruntime.com -e LETSENCRYPT_EM[email protected] -d --restart always wordpress
Configure
After I deploy the four containers, I will head to the URL and run the setup wizard.

As you can see the blog is up and running.

More Notes
To add a second website run another two containers and change the values.