Docker – How to analyze a container's disk usage?

I’ve been searching for a while, but couldn’t find a way to analyze the disk usage of a Docker container / volume.

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

  • Docker automated build from private bitbucket repo: Failed to clone repository
  • Docker killed by system when build
  • Docker Compose: Exposing Environment Variables to linked service
  • How to make changes to the code inside a Docker Container?
  • Use without the build-in NAT function but with DHCP
  • How to pass host IP as environment variable when running a docker container on OS X
  • 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?

    Many thanks,

  • Where is Docker storing the images? [closed]
  • Docker Compose with one Terminating Container
  • Azure App Service + Docker Autodeploy?
  • Powershell remote access to nanoserver on docker
  • Docker usage in compose/swarm mode
  • Restore a Postgresql database into a Docker container so when Postgres starts up the DB is in place
  • 8 Solutions collect form web for “Docker – How to analyze a container's disk usage?”

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

    docker ps -s

    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 -v

    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

    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 -h

    NOTE: Change ‘devicemapper’ according to your Docker filesystem (e.g ‘aufs’)

    The volume part did not work anymore so if anyone is insterested I just change the above script a little bit:

    for d in `docker ps | awk '{print $1}' | tail -n +2`; do
        d_name=`docker inspect -f {{.Name}} $d`
        echo "========================================================="
        echo "$d_name ($d) container size:"
        sudo du -d 2 -h /var/lib/docker/aufs | grep `docker inspect -f "{{.Id}}" $d`
        echo "$d_name ($d) volumes:"
        for mount in `docker inspect -f "{{range .Mounts}} {{.Source}}:{{.Destination}}                                                                                                                                                      
        {{end}}" $d`; do
            size=`echo $mount | cut -d':' -f1 | sudo xargs du -d 0 -h`
            mnt=`echo $mount | cut -d':' -f2`
            echo "$size mounted on $mnt"

    (this answer is not useful, but leaving it here since some of the comments may be)

    docker images will show the ‘virtual size’, i.e. how much in total including all the lower layers. So some double-counting if you have containers that share the same base image.


    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:

    Keep in mind that docker ps --size may be an expensive command, taking more than a few minutes to complete. The same applies to container list API requests with size=1. It’s better not to run it too often.

    Take a look at alternatives we compiled, including the du -hs option for the docker persistent volume directory.

    You can use

    docker history IMAGE_ID

    to see how the image size is ditributed between its various sub-components.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.