Menu
User

DropVPS Team

Writer: Cooper Reagan

How to completely clean a docker?

How to completely clean a docker?

Publication Date

12/30/2025

Category

Articles

Reading Time

2 Min

Table of Contents

Docker can slowly eat disk space with unused containers, images, volumes, and networks. If your VPS is running out of space or Docker is behaving weirdly, a full cleanup is often the fastest fix.

Step 1: Stop All Running Containers

Before cleaning, stop everything to avoid conflicts.

docker stop $(docker ps -aq)

If no containers exist, Docker will simply return nothing.

Step 2: Remove All Containers (Running + Stopped)

This deletes all containers, including exited ones.

docker rm $(docker ps -aq)

At this point, no containers should remain.

Step 3: Remove All Docker Images

This frees the largest amount of disk space.

docker rmi $(docker images -aq)

If images are in use, make sure Step 2 was completed successfully.

Step 4: Remove All Volumes (⚠️ Data Loss)

Volumes store persistent data (databases, uploads). This step permanently deletes them.

docker volume rm $(docker volume ls -q)

If Docker refuses, use force removal:

docker volume rm -f $(docker volume ls -q)

Step 5: Remove All Custom Networks

Docker networks also accumulate over time.

docker network rm $(docker network ls -q)

Default networks like bridge, host, and none may be skipped automatically.

Step 6: Full System Prune (Aggressive)

This is the fastest way to nuke everything unused.

docker system prune -a --volumes

What this removes:

  • All stopped containers

  • All unused images

  • All unused networks

  • All unused volumes

Confirm with y when prompted.

Step 7: Verify Docker Is Clean

Check that Docker is basically empty.

docker ps -a
docker images
docker volume ls
docker network ls

You should only see default Docker resources.

Optional Step: Reset Docker Storage Completely (Advanced)

If Docker is corrupted or disk usage still looks wrong.

sudo systemctl stop docker
sudo rm -rf /var/lib/docker
sudo systemctl start docker

This fully resets Docker as if it was freshly installed ⚠️
Use only if you know what you’re doing.

Linux VPS
U
Loading...

Related Posts