I have an image that I’ve created, pushed to my private registry, and pulled down to 2 different EC2 instances. Both are based on the same official ubuntu trusty AMI, although one is a t2.small and one a t2.micro. Both have the same size root volume (8GB), using the same filesystem (ext4).
On the t2.micro, using df -h I can see that the image takes up approximately 400MB, which is the same as the virtual size reported by docker image. On the t2.small instance however, the same image takes up around 4GB, and it’s impossible to create a container from this image as it exceeds the size of the root volume during creation.
Why is the image size so radically different on the two hosts? I understand that the actual size of docker images can be much greater than the virtual size, but I would expect it to at least be the same between 2 hosts, especially ones that are pretty much identical from a disk perspective.
Here’s the info for the servers, which is a before and after removal of the image. Host 1 is the server where the size does not seem to be out of proportion:
Host 1:
user@ip-y-y-y-y:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker.example.com/beaver 34.1.0 c283f8691f76 19 hours ago 404.9 MB
user@ip-y-y-y-y:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.8G 1.9G 5.5G 26% / <— docker images located here
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 492M 12K 492M 1% /dev
tmpfs 100M 396K 99M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 497M 0 497M 0% /run/shm
none 100M 0 100M 0% /run/user
user@ip-y-y-y-y:~$ sudo docker rmi c283f8691f76
user@ip-y-y-y-y:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.8G 1.5G 5.9G 20% / <— docker images located here
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 492M 12K 492M 1% /dev
tmpfs 100M 384K 99M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 497M 0 497M 0% /run/shm
none 100M 0 100M 0% /run/user
Host 2:
user@ip-x-x-x-x:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE docker.example.com/beaver 34.1.0 c283f8691f76 19 hours ago 404.9 MB
As you can see, removing the same image on Host 2 frees up around 4 - 5GB compared to ~400MB (also the virtual size of the image) on Host 1.
I should also mention that when I posted my original query, the docker images on the second host were actually located on the root volume (same as host 1). The sizes reported were exactly the same though. I just moved it to a larger volume so I could continue with my work.
well one way to look at this is to actually go into where the “image
layers” are stored and take a look one by one,
but the path is var/lib/docker/containers#
you will be able to see the size of each “image layer” with the command “du
-h -s -c”
I really dont know the best way to do this but this is all i got!!
I would love to know if there is a better way to do this
you might be able to correlate any sizes with image layer with the
"docker history" command this also seems to have this size as well!!
root@forncvlass:/var/lib/docker/containers# docker history 4bb
IMAGE CREATED CREATED BY
SIZE COMMENT
4bb63fa68da9 54 minutes ago /bin/sh -c #(nop) ENTRYPOINT
&{[“java” “Hello 0 B
137752d0f22f 54 minutes ago /bin/sh -c javac HelloWorld.java
421 B
ef41fa5613b3 55 minutes ago /bin/sh -c #(nop) COPY
file:cbae5ac9fb15120a5 104 B
0ad6528abdca 7 days ago /bin/sh -c apt-get update &&
apt-get install 294.7 MB
5eaaf6623273 7 days ago /bin/sh -c #(nop) ENV
JAVA_DEBIAN_VERSION=7u7 0 B
79dd8bb376bc 7 days ago /bin/sh -c #(nop) ENV
JAVA_VERSION=7u79 0 B
f431c2f455d3 7 days ago /bin/sh -c #(nop) ENV LANG=C.UTF-8
0 B
1be967a6306a 7 days ago /bin/sh -c apt-get update &&
apt-get install 789.4 kB
20b348f4d568 9 days ago /bin/sh -c apt-get update &&
apt-get install 122.3 MB
8b49fe88b40b 9 days ago /bin/sh -c apt-get update &&
apt-get install 44.36 MB
8c00acfb0175 9 days ago /bin/sh -c #(nop) CMD [”/bin/bash"]
0 B
843e2bded498 9 days ago /bin/sh -c #(nop) ADD
file:c7d957020a6ee3df60 125.2 MB
root@forncvlass:/var/lib/docker/containers#