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!
To update an existing Docker container manually, the following steps are necessary;
- Go to Registry and download new image (mostly the “latest” version)
- Go to Container, select the container you need to update and stop it
- From Actions menu select “Clear”
Edit: Under DSM7, the “Clear” command has been renamed “Reset”.
- 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.
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:
- Load image containrrr/watchtower in the Docker registry
- Sign in with root privilege via SSH
- 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.