docker-tidy/docs/content/usage/_index.md

56 lines
1.8 KiB
Markdown
Raw Normal View History

2020-03-15 13:21:36 +01:00
---
title: Usage
---
<!-- spellchecker-disable -->
2020-03-15 13:30:37 +01:00
{{< toc >}}
<!-- spellchecker-enable -->
2020-03-15 13:30:37 +01:00
2020-03-15 13:21:36 +01:00
## Garbage Collector
Remove old docker containers and docker images.
2020-06-03 22:40:20 +02:00
`docker-tidy gc` will remove stopped containers and unused images that are older than \"max age\". Running containers, and images which are used by a container are never removed.
2020-03-15 13:21:36 +01:00
2020-06-03 22:40:20 +02:00
Maximum age can be specified with any format supported by [dateparser](https://dateparser.readthedocs.io/en/latest/index.html#features).
2020-03-15 13:21:36 +01:00
2020-06-03 22:40:20 +02:00
**Example:**
2020-03-15 13:21:36 +01:00
```Shell
2020-03-15 14:50:58 +01:00
docker-tidy gc --max-container-age "3 days ago" --max-image-age "30 days ago"
2020-03-15 13:21:36 +01:00
```
### Prevent images from being removed
2020-06-03 22:40:20 +02:00
`docker-tidy gc` supports an image exclude list. If you have images that you\'d like to keep around forever you can use the exclude list to prevent them from being removed.
2020-03-15 13:21:36 +01:00
```Shell
--exclude-image
Never remove images with this tag. May be specified more than once.
```
### Prevent containers and associated images from being removed
2020-06-03 22:40:20 +02:00
`docker-tidy gc` also supports a container exclude list based on labels. If there are stopped containers that you\'d like to keep, then you can check the labels to prevent them from being removed.
2020-03-15 13:21:36 +01:00
```Shell
--exclude-container-label
Never remove containers that have the label key=value. =value can be
omitted and in that case only the key is checked. May be specified
more than once.
```
## Autostop
Stop containers that have been running for too long.
2020-06-03 22:40:20 +02:00
`docker-tidy stop` will `docker stop` containers where the container name starts with [\--prefix]{.title-ref} and/or it has been running for longer than [\--max-run-time]{.title-ref}.
2020-03-15 13:21:36 +01:00
2020-06-03 22:40:20 +02:00
If no prefix is set, **all** containers matching the `max-run-time` will be stopped!
2020-03-15 13:21:36 +01:00
2020-06-03 22:40:20 +02:00
**Example:**
2020-03-15 13:21:36 +01:00
```Shell
2020-03-15 14:50:58 +01:00
docker-tidy stop --max-run-time "2 days ago" --prefix "projectprefix_"
2020-03-15 13:21:36 +01:00
```