This short article documents an interesting project I wrote.

Goal

The goal is to run 10 WordPress sites in a kintohub free container service, which is a stateless container built from a dockerfile that you can fully customize.

This problem has two challenges:

  1. Because the container is stateless, whenever something happens to the container, all the data will be lost. We do not want that to happen.
  2. Because it is a single container, you cannot run the database and the WordPress sites each in separate containers. They will have to share the container.

Source Code

The source code is very simple. Write a Dockerfile with two lines, which starts from my docker image on dockerhub and add your config file:

Dockerfile:

1
2
FROM alicesu/single-container-wordpress:latest
COPY wp-docker-config.yml /etc/wp-docker-config.yml

The config file has a simple format, please refer to the documents of my docker image for details.

How is persistence achieved on a stateless container?

On a cron job defined in the configure file, the data is periodically dumped and backed up into Amazon S3. Every time the container is restored, either by accident or on purpose, the data is automatically restored from Amazon S3. Therefore, the stateless container feels as if it contains persistent storage.

Apparently this will not work very well for busy sites. However, if you have a very busy site, you shouldn’t be using this method in the first place.

Steps I used to deploy the project

  1. Create a github repository, and put the simple 2-line Dockerfile and config file: https://github.com/alicesu55/wp-test
  2. Create a free account and log in at https://app.kintohub.com
  3. Click “Add Service”, and select “Web App”.
  1. In the next page, click tab “Import Url” and then put in the address of my github repository. Note this is the repository of this demo project, not the source code for the docker image you want to reuse, which can be found here.
  1. Change the port to 80
  1. Set the environment variables to set up automatic backup and restore from S3. You will need a bucket name and all those AWS settings
  1. Deploy it

  2. After deploying, set up all the domain names you will want to use. For this demo, they are:

https://t0.alicesu.ml

https://t1.alicesu.ml

https://t2.alicesu.ml

https://t3.alicesu.ml

https://t4.alicesu.ml

https://t5.alicesu.ml

https://t6.alicesu.ml

https://t7.alicesu.ml

https://t8.alicesu.ml

https://t9.alicesu.ml

  1. Go to each of these URLs and set up the 10 sites. These WordPress sites are ready now.