Restart Docker container on image change
This blog is a static website served from a Docker container. The content is written in markdown and pushed to a Git repository hosted on GitHub. Every time I push to that repository a Docker image containing the new version is build on DockerHub.
While the new image is available on DockerHub there is still a container running containing the old version. Normally I would go to the server where the container is running and perform a manual
docker pull command and spin up a new container. I hated doing this manual step and automated it:
👉 The people from containrrr.dev made a simple to use piece of software called watchtower. This detects when the image of a container changes. When that happens the changed image is pulled and the container will be restarted. Watchtower can be started as an individual Docker container with the following command:
📓 if no name is given all containers are watched.
I like to configure and document my containers with a docker-compose file. This is also supported by watchtower.