Loading...

Show docker container size

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

If you build docker containers, ensure that you don’t write any data within the containers. Therefore you can use mapped volumes or data containers. Basically your docker containers that hosts the application or service should be immutable. I won’t go into details why, but how to check that a docker container does not grow.

Docker provided the ps command with the option -s or --size.

The command

sudo docker ps -s

will give some output. Depending how many containers you have, it can be a little bit unreadable. See example output:

tan@epsilon:~> sudo docker ps -s
CONTAINER ID        IMAGE                                   COMMAND                  CREATED             STATUS              PORTS                                                                                                                                                                                                                        NAMES                         SIZE
f68a2ba2b243        6fd8f0170256                            "/bin/sh -c '$JAVA_HO"   3 days ago          Up 3 days           0.0.0.0:33369->2251/tcp, 0.0.0.0:33368->8080/tcp                                                                                                                                                                             trusting_meitner              32.77 kB (virtual 410.3 MB)
390b7f2e559f        mongo:3.2.9                             "/entrypoint.sh mongo"   3 days ago          Up 3 days           27017/tcp                                                                                                                                                                                                                    kickass_yalow                 8 B (virtual 366.3 MB)
8e64707ad052        elasticsearch:2.4.0         "/docker-entrypoint.s"   7 days ago          Up 7 days                                                                                                                                                                                                                                        elasticsearch                 32.77 kB (virtual 413.4 MB)
a428d4a08dc6        14b6487a15bf                            "/bin/sh -c '$JBOSS_H"   9 days ago          Up 9 days           0.0.0.0:32908->8080/tcp    

Therefore docker provides the formatting option: Pretty-print containers using a Go template


sudo docker ps --format '{{.Names}}\n{{.Image}}:{{.Size}}\n' -s

The placeholders are described at Docker Reference ps formatting.

This will give us some more readable output:

elasticsearch
elasticsearch:2.4.0:32.77 kB (virtual 413.4 MB)

kibana
kibana-test:4.6.1:121.5 kB (virtual 661.7 MB)

suspicious_austin
716ee716f7bf:864.7 kB (virtual 664.3 MB)

services
8e28731dcc86:71.51 MB (virtual 1.425 GB)

mnorc
c18ea635a8ed:864.6 kB (virtual 664.3 MB)
Please remember the terms for blog comments.