2021-03-01 10:41:19 +00:00
---
title: 'Maintenance | Update and Cleanup'
---
2023-09-19 04:21:33 +00:00
[`containrrr/watchtower`][watchtower-dockerhub] is a service that monitors Docker images for updates, automatically applying them to running containers.
2017-07-28 16:44:22 +00:00
2023-09-19 04:21:33 +00:00
!!! example "Automatic image updates + cleanup"
2017-07-28 16:44:22 +00:00
2023-09-19 04:21:33 +00:00
```yaml title="compose.yaml"
services:
watchtower:
image: containrrr/watchtower:latest
# Automatic cleanup (removes older image pulls from wasting disk space):
environment:
- WATCHTOWER_CLEANUP=true
volumes:
- /var/run/docker.sock:/var/run/docker.sock
```
2020-05-29 03:58:54 +00:00
2023-09-19 04:21:33 +00:00
!!! tip "Updating only specific containers"
2021-03-01 10:41:19 +00:00
2023-09-19 04:21:33 +00:00
The default `watchtower` service will check every 24 hours for any new image updates to pull, **not only the images** defined within your `compose.yaml` .
2017-07-28 16:44:22 +00:00
2023-09-19 04:21:33 +00:00
The images to update can be restricted with a custom command that provides a list of containers names and other config options. Configuration is detailed in the [`watchtower` docs][watchtower-docs].
2017-07-28 16:44:22 +00:00
2023-09-19 04:21:33 +00:00
!!! info "Manual cleanup"
2017-07-28 16:44:22 +00:00
2023-09-19 04:21:33 +00:00
`watchtower` also supports running on-demand with `docker run` or `compose.yaml` via the `--run-once` option.
You can also directly invoke cleanup of Docker storage with:
2017-07-28 16:44:22 +00:00
2023-09-19 04:21:33 +00:00
- [`docker image prune --all`][docker-docs-prune-image]
- [`docker system prune --all`][docker-docs-prune-system] (_also removes unused containers, networks, build cache_).
- Avoid the `--all` option to only remove ["dangling" content][docker-prune-dangling] (_eg: Orphaned images_).
2021-03-01 10:41:19 +00:00
2023-09-19 04:21:33 +00:00
[watchtower-dockerhub]: https://hub.docker.com/r/containrrr/watchtower
[watchtower-cleanup]: https://containrrr.github.io/watchtower/arguments/#cleanup
[watchtower-docs]: https://containrrr.dev/watchtower/
2017-07-28 16:44:22 +00:00
2023-09-19 04:21:33 +00:00
[docker-docs-prune-image]: https://docs.docker.com/engine/reference/commandline/image_prune/
[docker-docs-prune-system]: https://docs.docker.com/engine/reference/commandline/system_prune/
[docker-prune-dangling]: https://stackoverflow.com/questions/45142528/what-is-a-dangling-image-and-what-is-an-unused-image/60756668#60756668