Skip to content

Instantly share code, notes, and snippets.

@javdl
Last active January 18, 2018 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javdl/c9d08e55bd658c180ddfbcbc177259ba to your computer and use it in GitHub Desktop.
Save javdl/c9d08e55bd658c180ddfbcbc177259ba to your computer and use it in GitHub Desktop.

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

Purging All Unused or Dangling Images, Containers, Volumes, and Networks

Docker provides a single command that will clean up any resources — images, containers, volumes, and networks — that are dangling (not associated with a container):

docker system prune

To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:

docker system prune -a

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

docker volume rm $(docker volume ls -qf dangling=true)
docker volume ls -qf dangling=true | xargs -r docker volume rm

delete networks

docker network ls  
docker network ls | grep "bridge"   
docker network rm $(docker network ls | grep "bridge" | awk '/ / { print $1 }')

remove docker images

// see: http://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images

docker images
docker rmi $(docker images --filter "dangling=true" -q --no-trunc)

docker images | grep "none"
docker rmi $(docker images | grep "none" | awk '/ / { print $3 }')

remove docker containers

// see: http://stackoverflow.com/questions/32723111/how-to-remove-old-and-unused-docker-images

docker ps
docker ps -a
docker rm $(docker ps -qa --no-trunc --filter "status=exited")

Resize disk space for docker vm

docker-machine create --driver virtualbox --virtualbox-disk-size "40000" default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment