Cookie Consent by Free Privacy Policy Generator Cleaning up Docker space | Igor Moiseev
Software

Cleaning up Docker space

Docker accumulates state silently — stopped containers, dangling image layers, unattached volumes, orphaned networks. Four short commands, run in the right order, reclaim gigabytes safely without touching anything that's currently running or in use.

By Igor Moiseev · · 1 min read ·

Regularly cleaning your dangling containers and images.

Step 1: cleaning containers, don’t worry it destroys only stopped containers

docker ps -aq| xargs docker rm

Step 2: removing dangling images

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

Docker itself offers a number of tools to prune and clean up space

  1. Inspecting docker filesystem: docker system df
  2. Pruning stopped containers: docker container prune
  3. Removing all local volumes: docker volume prune
  4. docker system prune will remove
    • all stopped containers
    • all networks not used by at least one container
    • all dangling images
    • all dangling build cache