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)

1
docker system prune

Or run individually:

1
docker container prune
1
docker volume prune
1
docker image prune
1
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.

1
docker system df
1
2
3
4
5
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