Synology: How do I update an existing Docker container with a new image?

container ship in port

As always: before you do such an update, make sure to create a backup of all your files. If something goes wrong, this may lead to data loss!

Manual update

To update an existing Docker container manually, the following steps are necessary;

  1. Go to Registry and download new image (mostly the “latest” version)
  2. Go to Container, select the container you need to update and stop it
  3. From Actions menu select “Clear”
    Edit: Under DSM7, the “Clear” command has been renamed “Reset”.
  4. Start the container again

This will clear the complete container and start with the newly downloaded Docker image. Since the data folders are mounted into the container, this will not erase the apllications data. Configurations are also not affected by this.

Side note: when updating a major version of gitlab/gitlab-ce, make sure to follow the update paths! This requires updates in smaller steps (minor versions).

Automatically update Docker images

Updating a Docker image manually might be fine for a small number of images. But there is a more elegant way by using another Docker container called Watchtower. This one can update Docker containers automatically. The image is called containrrr/watchtower. A simple setup can be performed with the following steps:

  1. Load image containrrr/watchtower in the Docker registry
  2. Sign in with root privilege via SSH
  3. Run the following code in the shell:
docker run -d --network host --name watchtower-once -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower:latest --cleanup --include-stopped --run-once

This will start the Watchtower image and update all container once. The container created for this runs once and can then be found switched off in the list of containers. Now you can start it manually again and again as needed or let it run at certain times via Synology Task Scheduler. The command for the task scheduler is then as follows:

docker start watchtower-once -a

Let Watchtower run permanently

Alternatively you can use the scheduler in Watchtower itself. If you want to start it every Monday at 4 a.m., then enter the following command on the shell:

docker run -e "TZ=Europe/Berlin" -d --restart unless-stopped --network host --name watchtower -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --cleanup --include-stopped --schedule "0 0 4 ? * MON"

It is important to set the time zone to your because otherwise you will have an offset to UTC. In addition, the container is not terminated but always restarted. Even if it crashed or the NAS was restarted. The last parameter uses the cron syntax for scheduling the task.

Photo by sergio souza on Unsplash

4 comments on “Synology: How do I update an existing Docker container with a new image?

  1. Thank you for this ‘how to auto update’ information! You’re a docker wizard 🙂

    I instead used Control Panel > Task Scheduler > Create, from the Web Admin GUI and used “Run as Root” and then the user-defined script of “docker start watchtower-once -a” as per your instructions. That way I can more easily manage the schedule and have visibility of the cronjobs running on my NAS without needing to SSH back in again.

    Thanks again

    1. Thank you for adding this detail. I didn’t use the Task Scheduler yet, but great to know that this is possible. Indeed, this makes it more easy by just using the Admin Web interface 😉

      Thanks

  2. Thank you for the guide to ‘Manual update’.

    I have seen way more complicated guides to updating a Docker Run container, but yours worked flawlessly.

Leave a Reply to AK86 Cancel reply

Your email address will not be published. Required fields are marked *