Imagine that your colleagues are developing something that eventually becomes a docker container,
we’ll call it docker101tutorial, hosted in your private docker registry and you want to always have the latest version deployed on your Docker host, well, we could do something like this:

Create a cron.sh file with this content:

#!/bin/sh
if grep -Fqe "Image is up to date" << EOF
`docker pull aironman/docker101tutorial:latest`
EOF
then
    echo "no update, just do cleaning"
    docker system prune --force
else
    echo "newest exist, recompose!"
    cd /path/to/your/compose/file
    docker-compose down --volumes
    docker-compose up -d
fi

Drop it somewhere you like:

$HOME/.docker/cron.sh

Create the task in cron:

cron -e

Put something like this:

0 0 8 1/1 * ? * sh $HOME/.docker/cron.sh

I have a fish memory for these things, as I can never remember the order of that pattern, so I end up using things like this to calculate the cron expression. This means, run the cron.sh script at 08:00 every day.

Now you can think that you don’t use Docker host, you use yml files in your kubernetes, openshift, whatever,
so you change the else part to launch the kubectl commands that you see necessary.

Obviously, for this to work, the development folks have to upload the container version,
creating a new tag. You can see the idea, right? let’s go periodically to ask the docker registry if there is a new version of the container.

If there isn’t, I, who am a bit of a beast and have my laptop full of images and containers, am loading in this script ALL the containers and images hosted on my hard drive. Don’t do it in the real world, and simply indicates that there is nothing to update.

To Crom!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s