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
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.
Then we can pull the desired images using docker pull
docker pull mysql
docker pull wordpress
The next step is to create a custom network
docker network create — subnet 192.168.10.0/24 — driver bridge webapp
The network can be verified in the ip addr command as well.
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
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.
Conclusion
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.