Reputation: 8635
In a scenario where a image extends from another image and so on, will this behavior increase the size of a custom image adding bigger layers?
For example: The image cbelleza/springboot-maven-s2i extends from alpine image, in this case the size of all dependencies would it be (115MB + 3.97MB) ?
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cbelleza/springboot-maven-s2i latest 3b92af74af2d 28 minutes ago 115MB
alpine latest 7328f6f8b418 2 weeks ago 3.97MB
Having a shared parent image that is referenced in multiple children images, does it reduce the size of those children images, or is better having a single image with all dependencies and commands included inside (apk, .gz, tar, etc)?
Upvotes: 1
Views: 713
Reputation: 36903
Q. In a scenario where a image extends from another image and so on, will this behavior increase the size of a custom image adding bigger layers?
Each layer apport a differential amount of data, and does not repeat the previous ones.
Think an image as a layer plus metadata. Think layers as a tree of dependencies. The size of an image is the sum of its pointed layer plus each ancestor.
Let's say:
[layer A, image alpine] -> [layer B, no image] .-> [layer C, image app 1]
|
-> [layer D, image app 2]
Size of image app1 = size(C) + size(B) + size(A)
Size of image app2 = size(D) + size(B) + size(A)
Q. In this case, the size of all dependencies would it be (115MB + 3.97MB)?
Yes, but the real size in the disk will be much smaller due to they share layers.
Q. Having a shared parent image that is referenced in multiple children images, does it reduce the size of those children images, or is better having a single image with all dependencies and commands included inside (apk, .gz, tar, etc)?
You can have 1 base image of 1GB and 100 children images of 1MB, the total disk space will be (roughly) = 1GB + 100*1MB ~= 2GB. And not 1GB + 100*(1MB + 1GB).
However, the size of each child image is still 1GB + 1MB.
The same concept is applied in a docker registry, which will reuse any previously pushed layer.
Some docs here
Upvotes: 1