docs: Revise update-and-cleanup.md (#3539)

* Update update-and-cleanup.md

spotify dockergc is UNMAINTAINED, they advice to consider using the `docker system prune` command instead.

"This repository has been archived by the owner on Feb 2, 2021. It is now read-only."

https://github.com/spotify/docker-gc

* Revise `update-and-cleanup.md`

Merges the image update + cleanup sections.

---------

Co-authored-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
This commit is contained in:
jpduyx 2023-09-19 07:21:33 +03:00 committed by GitHub
parent 539a7bc3bb
commit 8c0cfa0836
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,40 +2,41 @@
title: 'Maintenance | Update and Cleanup'
---
## Automatic Update
[`containrrr/watchtower`][watchtower-dockerhub] is a service that monitors Docker images for updates, automatically applying them to running containers.
Docker images are handy but it can become a hassle to keep them updated. Also when a repository is automated you want to get these images when they get out.
!!! example "Automatic image updates + cleanup"
One could setup a complex action/hook-based workflow using probes, but there is a nice, easy to use docker image that solves this issue and could prove useful: [`watchtower`](https://hub.docker.com/r/containrrr/watchtower).
A Docker Compose example:
```yaml
services:
```yaml title="compose.yaml"
services:
watchtower:
restart: always
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
```
```
For more details, see the [manual](https://containrrr.github.io/watchtower/)
!!! tip "Updating only specific containers"
## Automatic Cleanup
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`.
When you are pulling new images in automatically, it would be nice to have them cleaned up as well. There is also a docker image for this: [`spotify/docker-gc`](https://hub.docker.com/r/spotify/docker-gc/).
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].
A Docker Compose example:
!!! info "Manual cleanup"
```yaml
services:
docker-gc:
restart: always
image: spotify/docker-gc:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
```
`watchtower` also supports running on-demand with `docker run` or `compose.yaml` via the `--run-once` option.
For more details, see the [manual](https://github.com/spotify/docker-gc/blob/master/README.md)
You can also directly invoke cleanup of Docker storage with:
Or you can just use the [`--cleanup`](https://containrrr.github.io/watchtower/arguments/#cleanup) option provided by `containrrr/watchtower`.
- [`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_).
[watchtower-dockerhub]: https://hub.docker.com/r/containrrr/watchtower
[watchtower-cleanup]: https://containrrr.github.io/watchtower/arguments/#cleanup
[watchtower-docs]: https://containrrr.dev/watchtower/
[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