Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to analyze disk usage of a Docker container

I can see that Docker takes 12GB of my filesystem:

2.7G    /var/lib/docker/vfs/dir 2.7G    /var/lib/docker/vfs 2.8G    /var/lib/docker/devicemapper/mnt 6.3G    /var/lib/docker/devicemapper/devicemapper 9.1G    /var/lib/docker/devicemapper 12G     /var/lib/docker 

But, how do I know how this is distributed over the containers?

I tried to attach to the containers by running (the new v1.3 command)

docker exec -it <container_name> bash 

and then running 'df -h' to analyze the disk usage. It seems to be working, but not with containers that use 'volumes-from'.

For example, I use a data-only container for MongoDB, called 'mongo-data'.

When I run docker run -it --volumes-from mongo-data busybox, and then df -h inside the container, It says that the filesystem mounted on /data/db (my 'mongo-data' data-only container) uses 11.3G, but when I do du -h /data/db, it says that it uses only 2.1G.

So, how do I analyze a container/volume disk usage? Or, in my case, how do I find out the 'mongo-data' container size?

like image 838
AlonL Avatar asked Nov 05 '14 09:11

AlonL


People also ask

How much space is my docker container using?

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.

What docker command can be used to view the disk usage of docker images containers volumes and cache?

The docker system df command displays information regarding the amount of disk space used by the docker daemon.

How do you find the memory utilization of a container?

If you need more detailed information about a container's resource usage, use the /containers/(id)/stats API endpoint. On Linux, the Docker CLI reports memory usage by subtracting cache usage from the total memory usage.

Why is docker using so much disk space?

Docker takes a conservative approach to cleaning up unused objects (often referred to as “garbage collection”), such as images, containers, volumes, and networks: these objects are generally not removed unless you explicitly ask Docker to do so. This can cause Docker to use extra disk space.


2 Answers

To see the file size of your containers, you can use the --size argument of docker ps:

docker ps --size 
like image 129
Maxime Avatar answered Sep 30 '22 09:09

Maxime


After 1.13.0, Docker includes a new command docker system df to show docker disk usage.

$ docker system df TYPE            TOTAL        ACTIVE     SIZE        RECLAIMABLE Images          5            1          2.777 GB    2.647 GB (95%) Containers      1            1          0 B         0B Local Volumes   4            1          3.207 GB    2.261 (70%) 

To show more detailed information on space usage:

$ docker system df --verbose 
like image 38
Hemerson Varela Avatar answered Sep 30 '22 10:09

Hemerson Varela