If you’re like most developers, you probably use Docker to package and deploy applications. But what do you do if your application’s dependencies take up too much disk space? In this article, we’ll show you how to check disk space usage for Docker images and containers. We’ll also show you how to reduce the size of your images and containers. ..


With containerized applications running in isolated environments, it can be harder than usual to track down problems with applications using too much storage space. Fortunately, Docker provides commands for managing container disk usage.

Doing a Quick Check

And if you want to check how much space Docker is using, you can use the built in command docker system df, as well as the Linux command du to get the size of the entire directory.

This command shows static images, containers that have made changes to their filesystem (e.g., log files), and volumes bound to the containers.

However, this isn’t entirely accurate—here, I have many containers running, but they’re all storing data in bind mounts on the host OS, not volumes.

Cleaning Docker Images

Docker Images are different than running containers; they’re the files that you download from the Docker Hub to launch a container from. They’re usually pretty big, containing all the necessary code to run a basic OS and your application.

Each version of an image is separate, but it’s stored in layers, so multiple new versions won’t take up twice as much storage space. You can view all images with image ls:

Cleaning these is easy; you don’t want to remove images of running containers, of course, but removing old images is fine—they’ll simply be re-downloaded when needed.

You can prune all images, or manually delete one by ID:

Checking Running Container Usage

Containers are a bit trickier to track down, since they can use data in many different ways:

Underlying image: each container will need to store its image, but this is reused across containers. Modification layer: if a container writes to its filesystem, such as log files, it will be saved in a new layer on top of the underlying image. This is unique to each container. Volumes: containers can have virtual drives mounted to them, which store data directly on disk outside the Docker storage system. Bind Mounts: containers can optionally access directories on the host directly.

Everything except bind mounts will show up in docker system df output. If you want to view stats for each container, Docker provides a flag for the ps command to list the usage:

Here, this shows the size on disk, as well as the virtual size (which includes the shared underlying image). Since these containers aren’t using any storage outside their bind mounts, the size is zero bytes.

Debugging Mounts (Binds and Volumes)

To view mount usage, for both direct bind mounts and managed volumes, you’ll have to get the size of them from the host OS. If you don’t know where they are, you can run docker container ls to get a container’s ID, and then run docker inspect to grab the mount info:

Then, you can check the total size with du -sh:

Pruning Containers And Volumes

Docker never removes containers or volumes (unless you run containers with the –rm flag), as doing so could lose your data. However, you may have old data backed up that needs to be garbage collected.

Much like images, Docker provides a prune command for containers and volumes:

Manually Debugging

If you have direct access to the server running Docker, you can pop open a shell in the container:

and run du -sh on the entire thing, which will return all data, including the image size, data on bind mounts, and data in volumes.