entbit. Menu

Cologne, DE

Published
Length
2 min · 362 w
Filed under
Docker

Discover Hidden Space: Understanding Docker Storage Usage with docker system df.

Learn how to analyze and optimize Docker storage usage with the `docker system df` command. Discover practical tips for managing Docker images, containers, and volumes to reclaim disk space and improve system efficiency.

Hey there, 🐳

Remember when you first started using Docker and thought you had it all figured out? Well, I've been in the Docker game for quite a while now, and I'm still stumbling upon new tricks. Today, I want to share a nifty little command that blew my mind - docker system df.

Ever wondered how much space Docker is taking up on your machine? This command might be your new best friend. Let me show you what I mean:

docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          78        2         20.69GB   20.24GB (97%)
Containers      2         0         613.6kB   613.6kB (100%)
Local Volumes   24        1         1.393GB   1.345GB (96%)
Build Cache     180       0         26.36MB   26.36MB

Let's break this down:

  1. Images: I've got 78 images, but only 2 are active. That's 20.69GB of space, with a whopping 97% of it just sitting there!
  2. Containers: Two containers taking up barely any space, but they're not even running.
  3. Local Volumes: 24 volumes, but only one in use. There's 1.393GB here, with 96% of it being reclaimable.
  4. Build Cache: This is from building images. All 26.36MB of it is reclaimable.

That is a lot, right? Now, if you're like me, you're probably thinking, "Wow, I need to clean this up!" And you're right. Here's how we can reclaim that space:

docker system prune --all --volumes

This command is like a magic broom for Docker. It sweeps away all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes. But hold on a second before you run it!

Remember those volumes we saw earlier? There's another command to target those specifically:

docker volume rm $(docker volume ls -qf dangling=true)

This removes any volumes that are "dangling" - not associated with a container anymore.

Now, I can't stress this enough: Use these commands with caution. They're powerful, which means they can be destructive if you're not careful. Before running them, in a production environment, make sure you won't be removing anything you might need later.

So, there you have it! A little Docker housekeeping tip that might save you gigabytes of space (or even more).

Until next time, thanks for reading!

Niklas

Newsletter · entbit.

One email per post.

Deno, AWS, GitHub Actions and whatever I'm debugging. No spam.

Prefer not to hand over your real address? Use an alias from DuckDuckGo, Firefox Relay or Hide My Email.