Skip to content

Instantly share code, notes, and snippets.

@CHIP0K
Created May 21, 2023 13:17
Show Gist options
  • Save CHIP0K/ea251622f3f6682abc564139a8188db1 to your computer and use it in GitHub Desktop.
Save CHIP0K/ea251622f3f6682abc564139a8188db1 to your computer and use it in GitHub Desktop.
To clean the environment in the docker
#!/bin/bash
# Do not run if removal already in progress.
pgrep "docker rm" && exit 0
# Remove Dead and Exited containers.
docker rm $(docker ps -a | grep "Dead\|Exited" | awk '{print $1}'); true
# It will fail to remove images currently in use.
docker rmi $(docker images -qf dangling=true); true
docker rmi $(docker images -qa); true
# Clean up unused docker volumes
docker volume rm $(docker volume ls -qf dangling=true); true
# Clean old system logs
find /var/log/ -ctime +1 -type f -delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment