Skip to content

Instantly share code, notes, and snippets.

@kaustubhn
Created March 31, 2023 05:39
Show Gist options
  • Save kaustubhn/5055a076fa65b90032d2a9a4041cb0d9 to your computer and use it in GitHub Desktop.
Save kaustubhn/5055a076fa65b90032d2a9a4041cb0d9 to your computer and use it in GitHub Desktop.
Docker commands to clean dangling images, containers & volumes
# Check system usage for docker universe
docker system df
# Remove unsed containers
$ docker ps --filter “status=exited” -q | xargs -r docker rm --force
# or through a simpler built-in command
$ docker container prune --force
# Remove all containers
# WARNING use with caution
# docker ps -a -q | xargs -r docker rm — force
# Remove unused images
docker images -f “dangling=true” -q | xargs -r docker rmi -f
# or through a simpler built-in command
docker image prune
# WARNING use with caution
# NOTE: you cannot query all unused images through "docker images" command
$ docker image prune --all --force
# Remove dangling volume
docker volume ls -qf dangling=true | xargs -r docker volume rm
# or through a simpler built-in command
docker volume prune --force
# Clean docker build cache
DOCKER_BUILDKIT=1 docker builder prune --all --force
# Remove networks
# will remove all networks not used by at least one container
docker network prune --force
# Docker Bramha-astra
# Removes all below
# all stopped containers
# unused networks
# dangling images and/or unused images
# dangling volumes
# builder cache.
docker system prune --force --volumes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment