Skip to content

Instantly share code, notes, and snippets.

@M-Razavi
Created February 7, 2025 14:53
Show Gist options
  • Save M-Razavi/2b0c233a758a5e2712f1868c88f21c1d to your computer and use it in GitHub Desktop.
Save M-Razavi/2b0c233a758a5e2712f1868c88f21c1d to your computer and use it in GitHub Desktop.
Docker cleanup.md

Prune unused Docker objects

Imagges

clean up unused images

docker image prune

To remove all images which aren't used by existing containers

docker image prune -a

Containers

remove all stopped containers

docker container prune

only removes stopped containers older than 24 hours

docker container prune --filter "until=24h"

Volumes

remove all volumes not used by at least one container

docker volume prune

only removes volumes which aren't labelled with the keep label

docker volume prune --filter "label!=keep"

Networks

remove all networks not used by at least one container

docker network prune

only removes networks older than 24 hours

docker network prune --filter "until=24h"

Prune everything.

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
  • unused build cache
docker system prune --volumes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment