mirror of
https://github.com/openstf/stf
synced 2025-10-03 17:59:28 +02:00
Add a docker build helper for cleaning up untagged images.
This commit is contained in:
parent
5b7b011203
commit
dacac9ca1d
3 changed files with 48 additions and 0 deletions
31
docker/extras/README.md
Normal file
31
docker/extras/README.md
Normal file
|
@ -0,0 +1,31 @@
|
|||
# Docker build extras
|
||||
|
||||
Optional utilities for builders.
|
||||
|
||||
## docker-cleanup-dangling-images
|
||||
|
||||
Daily cleanup of dangling (untagged) images. If you don't clean up old images you may eventually run out of disk space.
|
||||
|
||||
First, copy the unit files into your build machine's `/etc/systemd/system/` folder.
|
||||
|
||||
```bash
|
||||
cp docker-cleanup-dangling-images.{service,timer} /etc/systemd/system/
|
||||
```
|
||||
|
||||
Alternatively `scp` can be much easier depending on your setup:
|
||||
|
||||
```bash
|
||||
scp docker-cleanup-dangling-images.{service,timer} root@a.b.c.d:/etc/systemd/system
|
||||
```
|
||||
|
||||
Now all you need to do is enable and start the timer.
|
||||
|
||||
```bash
|
||||
systemctl enable --now docker-cleanup-dangling-images.timer
|
||||
```
|
||||
|
||||
You can also trigger the cleanup job manually:
|
||||
|
||||
```bash
|
||||
systemctl start docker-cleanup-dangling-images
|
||||
```
|
8
docker/extras/docker-cleanup-dangling-images.service
Normal file
8
docker/extras/docker-cleanup-dangling-images.service
Normal file
|
@ -0,0 +1,8 @@
|
|||
[Unit]
|
||||
Description=Clean up dangling Docker images
|
||||
After=docker.service
|
||||
Requires=docker.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/env sh -c '/usr/bin/docker images -q --filter "dangling=true" | xargs -t --no-run-if-empty /usr/bin/docker rmi'
|
9
docker/extras/docker-cleanup-dangling-images.timer
Normal file
9
docker/extras/docker-cleanup-dangling-images.timer
Normal file
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=Run docker-cleanup-dangling-images.service daily
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 10:00:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
Loading…
Add table
Add a link
Reference in a new issue