How to analyze disk usage of a Docker container
To see the file size of your containers, you can use the --size
argument of docker ps
:
docker ps --size
After 1.13.0, Docker includes a new command docker system df
to show docker disk usage.
$ docker system dfTYPE TOTAL ACTIVE SIZE RECLAIMABLEImages 5 1 2.777 GB 2.647 GB (95%)Containers 1 1 0 B 0BLocal Volumes 4 1 3.207 GB 2.261 (70%)
To show more detailed information on space usage:
$ docker system df --verbose
Posting this as an answer because my comments above got hidden:
List the size of a container:
du -d 2 -h /var/lib/docker/devicemapper | grep `docker inspect -f "{{.Id}}" <container_name>`
List the sizes of a container's volumes:
docker inspect -f "{{.Volumes}}" <container_name> | sed 's/map\[//' | sed 's/]//' | tr ' ' '\n' | sed 's/.*://' | xargs sudo du -d 1 -h
Edit:List all running containers' sizes and volumes:
for d in `docker ps -q`; do d_name=`docker inspect -f {{.Name}} $d` echo "=========================================================" echo "$d_name ($d) container size:" sudo du -d 2 -h /var/lib/docker/devicemapper | grep `docker inspect -f "{{.Id}}" $d` echo "$d_name ($d) volumes:" docker inspect -f "{{.Volumes}}" $d | sed 's/map\[//' | sed 's/]//' | tr ' ' '\n' | sed 's/.*://' | xargs sudo du -d 1 -hdone
NOTE: Change 'devicemapper' according to your Docker filesystem (e.g 'aufs')