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?
You can use
to see how the image size is ditributed between its various sub-components.
The volume part did not work anymore so if anyone is insterested I just change the above script a little bit:
Improving Maxime's anwser:
docker ps --size
You'll see something like this:
When starting a container, the image that the container is started from is mounted read-only (virtual).
On top of that, a writable layer is mounted, in which any changes made to the container are written.
So the Virtual size (183MB in the example) is used only once, irregardless of how many containers are started from the same image - I can start 1 container or a thousand; no extra disk space is used.
The "Size" (2B in the example) is unique per container though, so the total space used on disk is:
183MB + 5B + 2B
Be aware that the size shown does not include all disk space used for a container.
Things that are not included currently are;
- volumes
- swapping
- checkpoints
- disk space used for log-files generated by container
https://github.com/docker/docker.github.io/issues/1520#issuecomment-305179362
After 1.13.0, Docker includes a new command
docker system df
to show docker disk usage.To show more detailed information on space usage:
If you want to reduce the size of many-layered images, I can recommend Jason Wilder's
docker-squash
utility. Get it from GitHub here: https://github.com/jwilder/docker-squashPosting this as an answer because my comments above got hidden:
List the size of a container:
List the sizes of a container's volumes:
Edit: List all running containers' sizes and volumes:
NOTE: Change 'devicemapper' according to your Docker filesystem (e.g 'aufs')