DEV Community

Cover image for Two-Tier WordPress architecture based on Containers

Two-Tier WordPress architecture based on Containers

Daily Tech Learning
・4 min read

This is a beginners level exercise for hosting a two-tier architecture on Docker Containers. WordPress is a monolithic application which was designed to work on shared servers, however to utilize the advantages of micro services, we need to segregate the data layer and the processing layer.

The first split is to split the database and the web application handled by WordPress. The architecture that we are going to deploy is as follows

Two tier WordPress architecture based on Docker Containers

To deploy this architecture, we are going to use the following Docker community images.

Mysql — Official Image | Docker Hub

Wordpress — Official Image | Docker Hub

First of all, we can search the images, using the docker search command.

using docker search to look for mysql images

Using docker search to find wordpress image

Then we can pull the desired images using docker pull

docker pull mysql

docker pull wordpress

docker pull wordpress

The next step is to create a custom network

docker network create — subnet — driver bridge webapp



The network can be verified in the ip addr command as well.

ip address will show the custom network created

Now we have a custom network created, we can spin up our containers with the required configuration

docker run -it — name wpdb_mysql — network webapp -e MYSQL_ROOT_PASSWORD=LHSWCVAbzS -d mysql:latest

starting the mysql container

We are going to use a custom port 8081 to expose it to the world for our WordPress server. The other parameters include the configuration of mySql database server. Node that as we are using a custom bridged network, in the host, I have just provided the container name as it would be accessible by name as well.

docker run — name wp — network webapp -p 8081:80 -e WORDPRESS_DB_HOST=wpdb_mysql -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD=LHSWCVAbzS -e WORDPRESS_DB_NAME=wpdb -d wordpress

Now, you can access your freshly installed website on your favorite browser as well.


In this tutorial, I just covered splitting up of the database and web application provided by WordPress using containers in a custom bridged network. Please provide your feedback for any scope of improvements.

Discussion (0)