ABHILASH CA
Junior Devops Engineer

As a fellow Docker user, I‘m sure you know how easy it is for old images, stopped containers, and unused volumes to accumulate, slowly eating away at your disk space. After running Docker for a while, you may discover GBs worth of old artifacts that aren‘t being used for anything useful.
Not to worry! In this guide, I‘ll show you how to thoroughly clean up Docker and free up space by removing old images, containers, volumes, networks and more. By the end, you‘ll have a lean and mean Docker installation.
Follow these tips, and you can reclaim tens of gigabytes of space easily. Let‘s dive in!
Before cleaning up Docker, it helps to understand what‘s typically eating up all your disk space in the first place:
Dangling images – These are layers and intermediate images that were built during the image creation process but are no longer associated with an image tag. They sit around taking up space.
Unused volumes – Volumes created but not mounted to any active containers.
Stopped containers – Exited containers still retain their full filesystem and configuration.
Build cache – Docker caches image layers to speed up subsequent builds, but these cache layers pile up.
Intermediate containers – Containers created as part of a build process but not committed to an image.
A single Docker image may consist of dozens of layers totalling GBs. So even with just a moderate number of images, your Docker host can be bloated with huge amounts of unused data.
Now let‘s go through how to effectively clean each of these up.
When you stop a container, it retains its full filesystem and configuration by default. So all those stopped containers from testing or development can really add up.
List all containers, running and stopped:
docker container ls -a
Delete a specific container by ID:
docker container rm container_id
To remove all stopped containers:
docker container prune
This will delete all containers in an Exited status. Confirm the deletion when prompted.
As a point of reference, deleting all stopped containers on my Docker host recently freed up 26GB! So it‘s always good to prune your stopped containers periodically.
Pro tip: To have Docker automatically delete stopped containers, use --rm when starting the container:
docker run --rm image_name
Now let‘s move onto removing unused images taking up space.
Unused images, sometimes called dangling images, are intermediate image layers and build cache created when building an image. They sit around hogging disk space unless you explicitly delete them.
To list your images:
docker image ls
Delete specific images by ID:
docker image rm image_id1 image_id2
But to really remove unused and dangling images, use Docker‘s pruning commands:
# Prune just dangling images
docker image prune
# Prune all images not used by existing containers
docker image prune -a
When I ran these on my machine, they freed up 9GB andDeleted over 500 unused images!
You can also filter images by age or label to clean up:
# Remove images older than 24 hours
docker image prune -a --filter "until=24h"
# Remove images without specific label
docker image prune --filter "label!=mylabel"
Repeatedly pruning old or dangling images ensures you only maintain the images you actually need.
Two other sources of Docker disk bloat are unused local volumes and networks.
List all volumes:
docker volume ls
Remove specific volumes by name:
docker volume rm volume_name
Prune all unused volumes:
docker volume prune
You can do the same for networks:
# List networks
docker network ls
# Remove by name/id
docker network rm network_name
# Prune all unused
docker network prune
Pruning removed 5 unused volumes and 4 orphan networks for me, freeing up a non-trivial amount of space.
Intermediate containers created during builds and the cache Docker uses to speed up subsequent builds contribute to disk usage.
Use the docker builder prune command to clean up just this build cache:
docker builder prune
Note this will not remove any running containers.
In my case, removing the build cache freed up 2GB alone!
Now that you‘ve cleaned up your Docker host, let‘s talk about some general strategies to prevent future buildup:
Following Docker best practices prevents wasted space from piling up in the first place.
Here are a few more advanced Docker cleanup commands to really scrub things down.
Delete just dangling images not used by any containers:
docker image prune --filter dangling=true
Remove containers created more than a certain time threshold:
# Containers more than 2 hours old
docker container prune --filter "until=2h"
Delete images without at least one container associated:
docker image prune --filter "dangling=false" -a
Remove just unused volumes:
docker volume prune --filter "dangling=true"
Clean up after Docker Compose by removing associated containers and images:
docker system prune --filter "label!=com.docker.compose.project"
So in summary, here are some key Docker cleanup commands:
I hope these Docker removal and pruning commands give you the knowledge to thoroughly clean up your Docker system.
Keeping Docker lean improves performance, saves disk space, and makes it easier to manage your whole Docker installation.
The key is periodically removing stopped containers, dangling images, unused volumes and networks, and build cache with Docker‘s built-in prune commands.
Combine these prune commands with habits to prevent future buildup, and you‘ll have a slim, optimized Docker host in no time!
Share this article
Loading comments...
© 2026 CloudHouse Technologies Pvt.Ltd. All rights reserved.