2 Commands to Quickly View Docker Disk Space Usage

Docker Logo

Introduction

Between downloading and playing with new container images, running different variations different containerized applications within Docker, and building various new containers it is easy for Docker to start taking up serious space on your host machine. If you run a lot of containers that require persistent volumes, Docker will create those localized volumes on your system in the background as the container is initializing. This can create a lot of Docker disk space usage.

Now, if you aren’t consistently running commands to clean up your Docker host, then all of those volumes, container images, and running containers can take up a lot of disk space. Now, it is simple to run the docker system prune command to automatically wipe your Docker host, but what if you wanted to dive into your setup and to view the docker disk space usage on your system? Thankfully, Docker has a built in solution that will allow you to view details on Docker disk space usage.

The Basic Command to View Docker Disk Usage

In order to view a summarized account for docker disk space usage on your docker host system, you can run the following command:

docker system df

This will output a table of what on your docker host is using up disk space. The output will summarize the different images, containers, local volumes, and build caches on your system and display the quantity of those items, many of those items are in use, how much size those items are taking, and how much space you will reclaim when you remove them.

When you run the above command, your output will be similar to the output below:

2 Commands to Quickly View Docker Disk Space Usage 1

Viewing More Details About Docker Disk Usage

Now, for some people, viewing the basic details of what is taking up space on their docker host will be all they need to start reclaiming space. Then there is the rest of us who prefer a more detailed output. Docker provides an easy way to view our Docker disk space usage. All we need to do is add the --verbose flag to the command. You can also use -v for short as seen in the example below.

docker system df -v

When you run the above command, you will be presented with more detailed information about what exactly is taking up the space on your Docker host. Information will be presented in four main categories, images space use, containers space use, local volumes space use, and build cache usage, as seen below:

Viewing Docker Disk Space Usage

Image Space Use

The section on images space use section will outline the repository that the image came from, it’s tag, the image identification number on your system, how long ago the image was added to your system, size, shared size, unique size, and how many containers that are currently using the image.

The shared size is an interesting statistic. Docker container images are made from various different layers and if these layers are identical, they can be shared across multiple container images in an effort to save space on your system. The shared size amount will show how much of a particular container image is being shared with another container.

Container Space Use

The containers space use section the above output allows you to view which specific containers are taking up space on your Docker host machine. This section outlines the container ID on your system, the image that the container is running, the command being ran in the container, how many local volumes are attached to the container, and the amount of space that the container is taking up on your system.

Depending on the base image that is being used in the container, most containers will not necessarily take up a lot of space on your system. Alpine linux is one of the more popular, lightweight base images that are used to create docker containers.

Local Volume Space Usage

The local volumes space usage section outlines the name of the volume, how many containers that it is attached too and how much space the volume is taking up. Keep in mind that local volumes are volumes that are within Docker that are created when you start a container that requires them, or when you create them by using the docker volume create command. Because of the persistent data that is stored in various volumes, they can take up a lot of space on your system. Docker disk usage will also increase because when you remove containers, the volumes that are automatically created with the container will remain on the system.

Local volumes are stored in the var/lib/docker/volumes folder on your system. This section does not include volumes that are bound to folders on the host machine.

Build Cache Usage

The items displayed in the build cache usage section are items used when building and rebuilding Docker container images images. This section will display the cache ID, type, how much space it is using on your Docker host, when the cache was created and when it was last used. Similar to the image space use section, the build case usage section outlines which image layers are shared across containers vs. which image layers are unique. If you use dockerfiles to build a lot of containers then your docker disk usage could increase because of the space required for build caches.

Conclusion

As you can see, using the docker system df command is the easiest and most efficient way to view which components within your Docker host system are taking up valuable space on your hard drive. With this information you can easily pick and choose which items you can delete that you don’t need and leave items on your system that you may choose to use later. More information about the commands in this article can be found in Dockers official documentation.

If you have any questions or suggesting regarding this post or Docker disk usage, please leave a comment below.

The article, 2 Commands to Quickly View Docker Disk Space Usage, first appeared on Codeopolis.

Be the first to comment

Leave a Reply

Your email address will not be published.


*