docker / Guides

Free Docker disk space without pruning volumes

First identify what consumes space and where application data lives. An unused Docker object can still be valuable to you.

Examples use Bash; consult the references for details of your environment.

Inspect before removing anything

docker system df -v
docker ps -a
docker volume ls

Compare image, container, volume and build-cache usage. Reclaimable space is a diagnostic estimate, not a deletion preview. Inspect important containers with docker inspect <container> and check their mounts before cleanup.

Choose a targeted cleanup

CommandWhat it removesWhat to check
docker image pruneDangling imagesWhether an old local build matters to you.
docker container pruneAll stopped containersTheir writable layers and configuration.
docker builder pruneEligible build cacheWhether rebuilding will be expensive.

Run only the command that matches your goal and read its confirmation. Removing stopped containers loses data kept only in their writable layers. Bind-mounted files and volumes are separate storage.

Understand broader cleanup

docker system prune

This broader command removes stopped containers, unused networks, dangling images and unused build cache. Volumes are not included by default. Adding -a also targets images not associated with any container, including tagged images you might otherwise reuse.

Omitting volume deletion does not guarantee that all application data survives: data stored only inside a removed container is lost. Back up important data first.

Verify the result and the limits

docker system df -v
docker ps -a
docker volume ls

Check that required volumes remain and that your application can access its data. Do not add --volumes or run docker volume prune as part of this workflow. docker compose down -v is also outside this cleanup plan.

Docker system prune has no dry-run option. On Docker Desktop, reduced Docker usage does not necessarily mean the virtual disk file immediately shrinks by the same amount.

References

All guides