Wordpress Docker

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 swarm

To make sure that the image are crated successfully: docker-machine ls Output:
NAME     DRIVER URL                     STATE
manager1 virtualbox tcp://  Running
node1    virtualbox tcp://  Running
node2    virtualbox tcp:// Running
Now you can login to your manager1 node docker-machine ssh manager1 and initialize the swarm mode docker swarm init --advertise-addr , 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 \
To add a manager to this swarm, run ‘docker swarm join-token manager’ and follow the instructions.

3. Add Worker Nodes

Now 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
Go ahead to node1, docker-machine ssh node1 and execute the command you obtained to join the swarm, here it is docker swarm join --token SWMTKN-1-0ml9lv1xoqo776q218ppdai9cu554ug6z7ijc7gwdz1og3ntam-2tmli0v8i2th0b4tbutpba380 Do the same process for node2. Let's go back to manager1 and check our nodes: docker node ls
i6h44jwu4civb94c7xkay1r6j  node1     Ready   Active
uw5a3ap783tup8zndu01o7efw  node2     Ready   Active
njvwqi8cr2n7pc1lzmb2ixlzc* manager1  Ready   Active     Leader
We can see that our swarm now has 3 node, 1 manager and two workers.


Till now we have created 3 machines with docker installed, initiated a docker swarm mode with 1 manager and 2 workers. In the next part we create,scale and remove services.  
{{ message }}

{{ 'Comments are closed.' | trans }}