Remove Old Docker Containers (Spring Cleaning)

If you just dabble with Docker, or use it regularly, you will build an arsenal of images and containers as you go along. From time-to-time we need to clear these out. This process used to be more complicated until the docker command implemented a simpler way using system prune.

Remove all ‘dangling’ things (stopped containers, volumes, images)

$
Copy to Clipboard
docker system prune

Or run individually:

$
Copy to Clipboard
docker container prune
$
Copy to Clipboard
docker volume prune
$
Copy to Clipboard
docker image prune
$
Copy to Clipboard
docker network prune

As you can see in our screenshot, we had already run the prune command, so there was nothing else to remove :( but it would tell you how much space has been made available.

docker clear out with system prune

If you’re still curious how much space is being used, we can use system df.

$
Copy to Clipboard
docker system df
1
2
3
4
5
Copy to Clipboard
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          7         0         3.439GB   3.439GB (100%)
Containers      0         0         0B        0B
Local Volumes   6         0         98.2MB    98.2MB (100%)
Build Cache     0         0         0B        0B