How to dockerize your Wordpress website - part 1
Wordpress has proved it self as the industry standard CMS solution for creating dynamic and rich content websites.
By powering more than 25% of the web, millions of companies rely on it as an entry point for their leads and potential customers.
When your website is the your most profitable channel for customers you can't afford to suffer from service interruptions or downtime otherwise you inbound marketing team will go crazy !In this article I will explain how you can avoid such situations using Docker, Docker Compose ,Docker Swarm & Docker Machine. This guide assumes that you are familiar with the above technologies plus Wordpress installation. The website will be a simple Wordpress instance with a custom theme.
1. Prepare 3 Nodes
First we have to prepare 3 nodes for the docker swarm, nodes can be anything from bare-metal devices, VMs, to AWS EC2 instances. In this guide, I will be using VirtualBox as Docker Machine driver to create 3 nodes with Boot2Docker image installed.
docker-machine create --driver virtualbox manager1
docker-machine create --driver virtualbox node1
docker-machine create --driver virtualbox node2
2. Create a swarmTo make sure that the image are crated successfully:
NAME DRIVER URL STATE manager1 virtualbox tcp://192.168.0.100:2376 Running node1 virtualbox tcp://192.168.0.101:2376 Running node2 virtualbox tcp://192.168.0.102:2376 RunningNow you can login to your manager1 node
docker-machine ssh manager1and initialize the swarm mode
docker swarm init --advertise-addr 192.168.0.100, notice that we used the I.P address from the list above. On my computer, this is the output:
Swarm initialized: current node (njvwqi8cr2n7pc1lzmb2ixlzc) is now a manager. To add a worker to this swarm, run the following command: docker swarm join \ — token SWMTKN-1-0ml9lv1xoqo776q218ppdai9cu554ug6z7ijc7gwdz1og3ntam-2tmli0v8i2th0b4tbutpba380 \ 192.168.0.100:2377 To add a manager to this swarm, run ‘docker swarm join-token manager’ and follow the instructions.
3. Add Worker NodesNow we will add the other two worker nodes to this swarm, to find out how a worker should join a swarm execute the below command in manager1 node:
docker swarm join-token worker
To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-0ml9lv1xoqo776q218ppdai9cu554ug6z7ijc7gwdz1og3ntam-2tmli0v8i2th0b4tbutpba380 192.168.154.2:2377Go ahead to node1,
docker-machine ssh node1and execute the command you obtained to join the swarm, here it is
docker swarm join --token SWMTKN-1-0ml9lv1xoqo776q218ppdai9cu554ug6z7ijc7gwdz1og3ntam-2tmli0v8i2th0b4tbutpba380 192.168.154.2:2377Do the same process for node2. Let's go back to manager1 and check our nodes:
docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS i6h44jwu4civb94c7xkay1r6j node1 Ready Active uw5a3ap783tup8zndu01o7efw node2 Ready Active njvwqi8cr2n7pc1lzmb2ixlzc* manager1 Ready Active LeaderWe can see that our swarm now has 3 node, 1 manager and two workers.