Skip to content

Instantly share code, notes, and snippets.

@pike00
Forked from bastman/docker-cleanup-resources.md
Last active July 31, 2022 19:40
Show Gist options
  • Select an option

  • Save pike00/e1b54a55a3c520925af1289446f1ced3 to your computer and use it in GitHub Desktop.

Select an option

Save pike00/e1b54a55a3c520925af1289446f1ced3 to your computer and use it in GitHub Desktop.
Docker Cleanup Guide

Docker Cleanup Guide

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

System Prune

docker system prune --volumes

WARNING! This will remove:

  • all stopped containers
  • all networks not used by at least one container
  • all volumes not used by at least one container
  • all dangling images
  • all dangling build cache

Delete Volumes

See chadoe/docker-cleanup-volumes for more info.

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

Remove Docker Images

See Stack Overflow - "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 Stack Overflow - "How to remove old and unused Docker Images"

docker ps
docker ps -a
docker rm $(docker ps -qa --no-trunc --filter "status=exited")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment