@@ -29,9 +29,15 @@ use the `--names` and `--exclude` command-line options to consider only a subset
2929of the containers.
3030
3131Exited and dead containers are as reported by Docker. Stale containers are
32- containers that are created but hasn't moved to any other state after a given
32+ containers that are created but have not moved to any other state after a given
3333timeout.
3434
35+ In addition, it is possible to forcedly remove ancient, but still running
36+ containers using the ` --ancient ` option. This might be a dangerous operation,
37+ and it is turned off by default.
38+
39+ [ cprune ] : https://docs.docker.com/engine/reference/commandline/container_prune/
40+
3541### Images
3642
3743All dangling and orphan images will be removed. This also provides filtering
@@ -43,6 +49,8 @@ Dangling images are layers that have no relationship to any tagged images.
4349Orphan images are images that are not used by any container, whichever state the
4450container is in (including created or exited state).
4551
52+ [ iprune ] : https://docs.docker.com/engine/reference/commandline/image_prune/
53+
4654### Volumes
4755
4856All "empty" dangling volumes will be removed. The script will count the files
@@ -53,8 +61,6 @@ volumes. Volumes that have a name that was automatically generated are
5361automatically selected. File count is achieved through mounting the volumes into
5462a temporary [ busybox] container.
5563
56- [ cprune ] : https://docs.docker.com/engine/reference/commandline/container_prune/
57- [ iprune ] : https://docs.docker.com/engine/reference/commandline/image_prune/
5864 [ busybox ] : https://hub.docker.com/_/busybox
5965
6066## Command-Line Options
@@ -70,10 +76,17 @@ dash, `--`.
7076
7177### ` -v ` or ` --verbose `
7278
73- This will increase the verbosity of the script, output will be sent to the
74- ` stderr ` and lines will contain the name of the script, together with the
75- timestamp. When used in interactive mode, the script will automatically colour
76- the log.
79+ This will select the verbosity of the script (default: ` info ` ), output will be
80+ sent to the ` stderr ` and lines will contain the name of the script, together
81+ with the timestamp. When used in interactive mode, the script will automatically
82+ colour the log. Available levels are: ` error ` , ` warn ` , ` notice ` , ` info ` ,
83+ ` debug ` .
84+
85+ ### ` --non-interactive ` , ` --no-colour ` or ` --no-color `
86+
87+ Forcedly remove colouring from logs. Otherwise, logs will be coloured in
88+ interactive mode, but kept without colouring when invoked within pipes or
89+ without a (pseudo-)tty.
7790
7891### ` -h ` or ` --help `
7992
@@ -83,7 +96,7 @@ Print out help and exit.
8396
8497Just print out what would be perform, do not remove anything at all. This option
8598can be used to assess what the script would do when experimenting with options
86- such as ` --names ` , ` --exclude ` or ` --age ` .
99+ such as ` --names ` , ` --exclude ` , ` --age ` or ` --ancient ` .
87100
88101### ` -r ` or ` --resources `
89102
@@ -112,7 +125,17 @@ that should be kept.
112125### ` -a ` or ` --age `
113126
114127Age of dangling images to consider for removal (default: ` 6m ` ). The age can be
115- expressed in human-readable format, e.g. ` 6m ` (for 6 months), ` 3 days ` , etc.
128+ expressed in human-readable format, e.g. ` 6m ` (for 6 months), ` 3 days ` , etc. Set
129+ this to an empty string to skip removal of named dangling images totally.
130+
131+ ### ` --ancient `
132+
133+ Age of running containers to consider for removal (default: empty). The age can
134+ be expressed in human-readable format, e.g. ` 6m ` (for 6 months), ` 3 days ` , etc.
135+ Unnamed containers or containers that match the ` --names ` and ` --exclude ` filter
136+ and exclusion will be forced removed. This operation cannot be undone! The
137+ default is an empty sting, in which case no running container will ever be
138+ stopped and removed.
116139
117140### ` -t ` or ` --timeout `
118141
@@ -142,6 +165,21 @@ parsed at run-time to detect if containers are "unnamed" containers.
142165 [ source ] : https://raw.githubusercontent.com/moby/moby/master/pkg/namesgenerator/names-generator.go
143166 [ golang ] : https://golang.org/
144167
168+ ## Environment Variables
169+
170+ This script also recognises a number of environment variables, these can be used
171+ instead of (some of) the command-line options. Command-line options always have
172+ precedence over the environment variables. Recognised variables are:
173+
174+ - ` BUSYBOX ` : same as ` --busybox `
175+ - ` MAXFILES ` : same as ` --limit `
176+ - ` NAMES ` : same as ` --names `
177+ - ` EXCLUDE ` : same as ` --exclude `
178+ - ` RESOURCES ` : same as ` --resources `
179+ - ` AGE ` : same as ` --age `
180+ - ` ANCIENT ` : same as ` --ancient `
181+ - ` TIMEOUT ` : same as ` --timeout `
182+
145183## Docker
146184
147185This script also comes as a Docker [ image] . To be able to run it from a
@@ -163,7 +201,7 @@ to double check what the command would do...
163201``` shell
164202./prune.sh \
165203 --verbose debug \
166- --names ' ^runner-[[:alnum:]]+-project-[0-9]+-.*' \
204+ --names ' ^runner-[[:alnum:]_ ]+-project-[0-9]+-.*' \
167205 --age 2d
168206```
169207
0 commit comments