How to Reclaim Disk Space: Master Docker System Prune and Cleanup Commands
This guide explains why Docker can consume large amounts of disk space and provides step‑by‑step commands for regular pruning, image, container, network, and volume cleanup, as well as a one‑command full system purge to restore a clean Docker environment.
Overview
Docker does not modify system configuration but can consume large disk space. After using it for a while you may be shocked by the statistics. Below are before‑and‑after size figures.
Usage Statistics
PS C:\Users\Tinywan> docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 16 7 5.753GB 3.81GB (66%)
Containers 7 7 49.62MB 0B (0%)
Local Volumes 3 0 0B 0B
Build Cache 320 0 2.463GB 2.463GBRegular Pruning
To safely delete stopped containers, unused networks and dangling images, run the following command periodically:
docker system pruneA slightly riskier option is:
docker system prune -aThis also removes any images not referenced by a running container. The first run may be slower because Docker will need to re‑download required images, which are cached afterwards.
Image Reclamation
Docker images are disk snapshots of applications such as web servers, runtimes or databases.
List all images, including dangling ones: docker image ls -a Delete specific images: docker image rm <name_or_id> You can specify multiple image IDs separated by spaces.
Container Cleanup
Containers are runtime instances of images. List all containers (running and stopped): docker container ls -a Stop a container before removal: docker container stop <name_or_id> Remove a stopped container: docker container rm <name_or_id> The --rm flag can be added to docker run so the container is automatically removed when it exits.
Network Cleanup
Docker networks enable containers to communicate. List networks: docker network ls Remove unused networks:
docker network rm <name_or_id>Volume Optimization
Volumes store persistent data. List volumes: docker volume ls Delete an unused volume: docker volume rm <name> Remove all unused volumes in one step:
docker volume pruneFull System Cleanup
Erase every unused container, image, volume and network with a single command: docker system prune -a --volumes Add the -f flag to skip the confirmation prompt. After execution the system returns to a state with no Docker data.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
