This blog post is a very bad idea if you are doing this in your professional life. Nonetheless, this works perfectly for your low traffic and low impact website on your cheap vps.

The problem

I dont want to concern myself with connecting to vpn, logging in on my vps, stopping an docker image, pulling a new docker image, starting the image again. It is very boring to do for each change you make.

Docker orchestration engines, like kubernetes, are way to big to host on my vps. A few docker images don’t need automated orchestration, I have no scaling option.

So some prerequisits:

  • Single host
  • Low traffic and low impact website
  • Docker
  • Docker compose
  • systemctl
  • crons

The solution

It is easy, and it is ugly. Managing your docker container with dockercompose, adding it as a service to systemctl, and restarting it nightly.

Step 1, docker-compose your image

Create a docker-compose.yml with the following contents:

version: '2'
    image: image/site:latest
      - 80:80
    restart: always

Easy as such, it pulls your image from docker hub, and runs it.

Step 2, create a service config

This makes sure your docker image could be run as a service, which makes it easier to manage on your command line.

Create a file called website.service in /lib/systemd/system

Description=Website Service

ExecStartPre=/usr/local/bin/docker-compose -f /path/to/docker-compose.yml pull
ExecStart=/usr/local/bin/docker-compose -f /path/to/docker-compose.yml up
ExecStop=/usr/local/bin/docker-compose -f /path/to/docker-compose.yml down


Reload the daemon

systemctl daemon-reload

Your service should now be available, test it!

systemctl start website

Your website should now run as a service!

Step 3, automate “deployment”

This is the lamest solution ever, but if it works, is it lame?

Edit your crontab, and add the line:

00 00 * * * systemctl restart website

Each midnight it will pull the latest docker image, and enable it.

There we have it, Simple Automated docker deployment for barbarians