Image size different between hosts

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.

Any info would be greatly appreciated, thanks!

Please post your Dockerfile or docker-compose … and a screenshot of your df -h result.

Sure, here is the docker file: http://pastebin.com/ayeggz1n

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

user@ip-x-x-x-x:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.8G 1.6G 5.8G 22% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 996M 12K 996M 1% /dev
tmpfs 201M 388K 200M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1001M 0 1001M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/xvdb1 4.8G 122M 4.5G 3% /var/lib/mysql
/dev/xvdf1 99G 4.9G 89G 6% /var/lib/docker <— docker images located here

user@ip-x-x-x-x:~$ sudo docker rmi c283f8691f76
user@ip-x-x-x-x:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.8G 1.6G 5.8G 22% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
udev 996M 12K 996M 1% /dev
tmpfs 201M 380K 200M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 1001M 0 1001M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/xvdb1 4.8G 122M 4.5G 3% /var/lib/mysql
/dev/xvdf1 99G 76M 94G 1% /var/lib/docker <— docker images located here

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.

Thanks,
Guy

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

correction it looks like you want to run du -h -s in
var/lib/docker/containers# the result looks like this

root@forncvlass:/var/lib/docker/containers# du -h -c
36K ./589288f94acdf19c11ab50ebcfc870811b572a0a31adbbfe37aa8f7d9e107cd4
32K ./db1bb2eec8c6880045d00aa0976b90058160ee402e23aac9b37febd6d5cef54c
32K ./c727bf9b7e8671380b772d85126db3c25182bc817919ea1565b74486ac9a522f
32K ./cfd44fc1bddf21e66cc124e5cbd3d6f7de03cb23ffaeb078f5be670f790214c8
60K ./ae6c498b2c1a8d0d32830ba065511f8c0f10a77b6cd2d04f4604b966722b55c2
28K ./959b9455a0ea4997b7452f3c20c1474011d3aa30afba99e38d61b7670829eb4d
60K ./339a1258ce5ba1b2bed71a512b5d71fbc0821021de9908baae49e5f2c321d838
32K ./224f89d8ed76cf9466b994407a1c26b04708b481044ba9b2455619ec10731bbd
32K ./915edfa3152c0e566b5e601ffea2f08459c9ee761fc52c23b3e727a89a28f5e5
32K ./ae4febca5a0737c568ba2176d62cc63bd5ee3eb0906cae4c64928f3cb3ae2a67
32K ./cc4d521617932a5322ae88654f68a412694c51b038229cb8abee347e0d4fe1fd
32K ./e5a4a8699f076a5f6740c8806cbabc840350a5e05e7f6bdf574e0f65d9ab8d5c
32K ./909a0fec1678edeff8f62d4611a84a7b9b8a04082e3f87ab56112129494cbae3
36K ./3221209ffa3342530c7d5108a2087c502ab580e0ac9bb4222d1db55ff331ba75
32K ./208216bc4401568f2f293ab3c9ad9033524b80a1b4bd4798473caee5ff2efc94
32K ./5ee65ba1d0da5237496bd566ac75e0156d0f89dd00318cf96d21fbfe1515fac4
32K ./dea3000f0b7529351597cb59839ce0db18287a2ec893158252800cd197e22347
28K ./61d1e5c01b72cfdaac39a4ba4e398803e4c296c66a8b1d85f5b86b2a2833248b
636K .
636K total
root@forncvlass:/var/lib/docker/containers#

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#