Skip to content

Instantly share code, notes, and snippets.

@mleyb
Created June 28, 2017 18:15
Show Gist options
  • Save mleyb/64c7d982ec902e94b862895f0d771ae0 to your computer and use it in GitHub Desktop.
Save mleyb/64c7d982ec902e94b862895f0d771ae0 to your computer and use it in GitHub Desktop.
Docker Clean-up commands
For docker verison >= 1.13
If you are using docker version 1.13 and above, the following commands will do the trick.
Complete System Cleanup
To clean up, all unused containers, images, network, and volumes, use the following command.
docker system prune
Recommended: Learn Docker Technologies for DevOps and Developers8
To individually delete all the components, use the following commands.
docker container prune
docker image prune
docker network prune
docker volume prune
For Docker versions below 1.13
To clean up containers, first, you need to clean up your containers. So that all the unwanted images can be deleted without dependency problems.
Delete all Exited Containers
docker rm $(docker ps -q -f status=exited)
Delete all Stopped Containers
docker rm $(docker ps -a -q)
Delete All Running and Stopped Containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
Delete all "none" Images
docker rmi $(docker images | grep "^<none>" | awk '{ print $3 }')
Delete all Dangling Images
sudo docker rmi $(sudo docker images -f "dangling=true" -q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment