With this tutorial you will learn how to :

Deploy a brand new wordpress blog

Schedule automated backups of both the database, and the blog itself

Setup an automated backup recovery. Just in case.

Since docker is awesome, we are going to use it and profit of the following benefits:

No installation of anything is required. No server configuration. No development environment. No apache configuration. No ssh. Use your grandMa's computer if you wish.

is required. No server configuration. No development environment. No apache configuration. No ssh. Use your grandMa's computer if you wish. No code required, everything has already been done for you.

Easy to scale : migrating your blog from one server to another (bigger?) server is a matter of a few seconds.

0. Prerequisites

To follow this tutorial you will need to create an account on docker cloud, and you will need access to a cloud provider, such as aws. In this tutorial I will focus on a aws-based infrastructure.

1. Write a stack YAML file

In docker-cloud, a stack represents a list of services that will work together. It is very similar to a docker-compose file.

This file will "orchestrate" the different containers we will use and tell docker-cloud how to install containers on the node.

To begin with, let's put a wordpress image, linked to a mysql base:

As you can probably guess, this file tells docker-cloud to:

create a wordpress container called "web". This container should be linked to another container called "mysql", which is… a mysql image.

The environment variables are to declare a root password for the database, and we tell "web" to use it.

Use a "data" container that will be used to mount volumes. This would allow to persist data if the "web" or "mysql" containers were to be redeployed. It will also be helpful later on, to perform backups since all the relevant data can be accessed directly by connecting the "data" container

Now let's install the "backup" and "restore" services:

Obviously, you will need to provide your own access keys.

For the backup we use the tutum/dockup docker image. As described here, this container will take what is described in the PATHS_TO_BACKUP environment variable, and put it on a specified S3 bucket.

If the RESTORE env is set to true, then it will do the opposite, and put back to the server the last backup from s3.

Note that since we are sharing volumes with the "data" container, both the "backup" & "restore" containers will see the exact same files as "mysql" & "web" see on /var/lib/mysql and /var/www/html/wp-content.

Therefore, when copying or replacing any file in /var/lib/mysql from the "backup" container, we are actually changing the files that "mysql" uses. Neat !

The final YAML is the following:

2. Deploy everything !

At this point we "installed" everything we need and we are ready to roll !

And yes, it is that simple.

To deploy you can either use the cli-tool or the web ui. I'll show you how to do it "manually".

Browse https://cloud.docker.com/stack/launch/ , upload your yml file and click "Create stack"

From the "Nodes" tab, launch a new node cluster if you don't already have one running:

Browse to your stack and launch "data" (it will stop shortly after you launch it)

launch "mysql"

launch "web"

At this point you should have something that looks like that:

And that's it ! you can browse you brand new blog using the IP address given in the "Nodes" tab to see your brand new blog !

3. Bonus 1 : automated backup/recovery

Launching or redeploying the "backup" service will trigger a backup. To make this step automatic, you can add a 'trigger' to redeploy the backup service (see the docker doc if you are lost).

This will give you a webhook that you can call every morning so the backup is run.

At Hunteed we scheduled a task using iron.io worker, since they support docker as well.

If you'd like to, feel free to use our iron-curl image as follows:

declare a new worker on iron.io : iron register hunteed/iron-curl

schedule a recurring task on iron with a payload such as {"args":"-X POST http://my-endpoint-from-dockercloud.io"}. (curl will be called with whatever is put in the "args" key as arguments)

profit, and let us know if that helped :)

4. Bonus 2 : how to recover

Everything is crashed, the latest installed plugin made it all worse, and you wish everything could be the same it was this morning !

no problem : simply run the "recover" container from docker-cloud service. it will start, then stop. You'll probably need to re-run the 'web' and 'mysql' services as well. It's a matter of seconds anyway.

A few moments later, your blog is back as it were on last backup. Yay !

Hope this helped, happy blogging !