Use Watchtower to update automatically the running docker containers
Watchtower can be used either as standalone docker container or in docker compose.
- Create config.json Before creating the config file we need to get the username and password of Container Register in base64 encoded string.Containerregister can be Dockerhub,Azure Container Register or private container register.
Run on bash :
echo -n 'username:password' | base64
Or in powershell:
$UsernamePass = ‘username:password’
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($UsernamePass)
$EncodedText =[Convert]::ToBase64String($Bytes)
$EncodedText
Then create config.json :
{"auths": {"mycontainerregister.azurecr.io":{"auth": "TheEncodedBase64string"}}}
- Run watchtower as standalone
docker run -d \ -
-name watchtower \
-v /home/<user>/.docker/config.json:/config.json \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower container_to_watch --debug --interval 300 --include-restarting --cleanup
- Run watchtower in docker compose
watchtower:
image: containrrr/watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /home/<user>/.docker/config.json:/config.json
command: --debug --interval 300 --include-restarting --cleanup
In both examples watchtower:
- runs in debug mode
- with interval 5 minutes
- includes restaring running containers
- removes the old images after updating