Deploy and scale WordPress with Docker Cloud Swarm mode

WordPress with Docker Cloud.

Docker Cloud is a powerful tool that allows us to automate image builds, provision docker nodes, and create CI/CD pipelines. A month ago Docker introduced swarm mode for the Docker Cloud. And now teams and individuals can create and manage new or register their existing swarms and operate with them with docker id.

Our goal is to create a new swarm and deploy scalable WordPress.

Image.

Before we begin we should link our docker cloud to Amazon Web Services. After this procedure, we can create swarms with several clicks.

Let’s create our WP swarm and choose EC2 instance type and a number of manager and worker nodes below (I hope Docker Team will add a possibility to select different instance types for labeled groups of worker nodes).

Docker Cloud Swarm Mode.

To persist our data we will use EFS and we should remember that only three regions offer efs support in NA.


After clicking the Create button it will take about five minutes to deploy swarm on Amazon. Docker Cloud uses CloudFormation template, the final result looks like this

Deploy Swarm on Amazon.

To get instructions on how to connect to the new swarm just click on it when the status changed to deploy.

Connect to the Swarm.

I’ve created swarm with three managers and two worker nodes:


Now let’s create temporary wordpress service to test our swarm.

We need secrets for our database:


overlay network:


and MariaDB service:


And finally run WordPress:


Every published port will be automatically added to the ELB entrypoint and we can proceed WP installation using web wizard:

WP Installation Using Web Wizard.

That’s simple and great but with this WordPress instance we have several issues:

  • No SSL
  • No Persistance
  • No Scalability (we can scale WordPress service, but wp-content will be different in all containers)

Let’s destroy this WP service and try to fix those issues with


If you deploy swarm to the EFS-compatible region Docker Cloud will install cloudstore:aws storage driver to every node, and this allows you to mount EFS storage as a docker volume. By default this driver uses general purpose EFS. For MariaDB service we will use maxio option. Also we will start traefik service to generate LetsEncrypt SSL and serve our vhost.

Here is our docker-stack.yml:


Before start we should create CNAME wp.maddevs.io pointing to our ELB entrypoint. Then create networks and database secrets:


And deploy stack:


Now we can open our WordPress url https://wp.maddevs.io/ with http to https redirect.

And now we can scale traefik and wp manually:


Or by editing deploy section in our yml and redeploy stack.

Image.

We didn’t create more complicated infrastructure using another Amazon services like RDS, S3 + CloudFront, Elastic Cache etc but example above shows us the perfect symbiosis of cloud hosting and swarm mode with new docker >v1.13 features. Docker Cloud swarm mode removes our concerns about infrastructure and swarm management.

And it’s only beta.

Free Boilerplate to Run Kubernetes on AWS.
Run Kubernetes on AWS.

A true easy way to run Kubernetes on AWS

A true easy way to run Kubernetes on...

A true easy way to run Kubernetes on AWS

Let me be honest with you — I often feel being a Luddite. Not that I am against progress or trying to stop the hype train, no. But I often think that...

Boilerplate for Basic AWS Infrastructure with EKS Cluster.

Free boilerplate to run Kubernetes on AWS

Free boilerplate to run Kubernetes on...

Free boilerplate to run Kubernetes on AWS

Kubernetes is very useful, there is no doubt about it. But if you are just starting with it or if you haven't used it for ages, there is tons of...

LinuxKit as an ECS-instance with Terraform.

LinuxKit as an ECS-instance with Terraform

LinuxKit as an ECS-instance with...

LinuxKit as an ECS-instance with Terraform

When Docker offered convenient way to build, ship, and run applications with their unique runtimes independently inside containers the next was to...