Skip to content

Instantly share code, notes, and snippets.

@jcmartins
Last active August 1, 2017 15:27
Show Gist options
  • Save jcmartins/6af1878a92d4ab7b071a to your computer and use it in GitHub Desktop.
Save jcmartins/6af1878a92d4ab7b071a to your computer and use it in GitHub Desktop.
Cleanup Docker
Delete all containers
docker rm -v $(docker ps -qa)
-v remove the volume
Delete all images
docker rmi $(docker images -q)
docker rmi $(docker images -q -f "dangling=true")
Removes all containers running under Docker, so use with caution.
docker ps -a | awk '{print $1}' | xargs docker kill
Removing all Containers that are not running:
docker rm $(docker ps --filter "status=exited" -q --no-trunc)
-a is not needed when using --filter status=exited.
-f allows you to filter your list of printed containers (in this case we are filtering to only show exited containers)
-q prints just the container ids (without column headers)
Now this removes all the dangling non intermediate <none> images:
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
docker volume rm $(docker volume ls -q -f "dangling=true" )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment