Skip to content

Instantly share code, notes, and snippets.

@noyb34
Created August 29, 2017 16:30
Show Gist options
  • Save noyb34/3e4b43045ad2c34e4612ea674474379f to your computer and use it in GitHub Desktop.
Save noyb34/3e4b43045ad2c34e4612ea674474379f to your computer and use it in GitHub Desktop.
config
# Create /etc/systemd/system/docker-cleanup.timer with this content:
[Unit]
Description=Docker cleanup timer
[Timer]
OnUnitInactiveSec=12h
[Install]
WantedBy=timers.target
# And service file /etc/systemd/system/docker-cleanup.service:
[Unit]
Description=Docker cleanup
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
WorkingDirectory=/tmp
User=root
Group=root
ExecStartPre=-/bin/bash -c 'docker ps -aqf status=exited | xargs docker rm -v'
ExecStartPre=-/bin/bash -c 'docker images -qf dangling=true | xargs docker rmi -f'
ExecStart=/bin/docker ps -af status=exited
[Install]
WantedBy=multi-user.target
# run systemctl enable docker-cleanup.timer for enabling the timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment