Shared image layers

I have a multi container application with multiple containers based on the same base image. When I inspect the image sizes on a device, the application images take a considerable amount of storage space. Is there a way to deploy the application so the base image layer is shared between application images, in order to reduce download sizes?

Hi there! Could you provide some info on the steps you 've been using for verifying the RX bandwidth actually used? Also, how are you checking the image sizes?
Images using the same base layer, include its size on the total image size reported per image (via balena images for example), however, the base image should be downloaded and saved just once.

I have not checked the actual used bandwidth, but would be happy to be able to.

I checked the image sizes looking into the balenaCloud release tab. What I also did was ssh into the device and:

root@f14c40f:~# balena-engine images                                                                                                                   
REPOSITORY                                                       TAG                 IMAGE ID            CREATED             SIZE                      
registry2.balena-cloud.com/v2/da791489804e3628b36cfefbe4657c4a   <none>              675475b4ea43        20 hours ago        115MB                     
registry2.balena-cloud.com/v2/7ce9d187833ad1a3b41607000743121d   <none>              2d99eb6d7129        21 hours ago        87.5MB                    
registry2.balena-cloud.com/v2/365219cd1d0ffb5f293b6cabe0f47556   <none>              509de069ec1a        22 hours ago        86.7MB                    
registry2.balena-cloud.com/v2/6283c51a4f530de9973a95e4e8ad0f10   <none>              3b372cb651c7        2 days ago          54.5MB                    
registry2.balena-cloud.com/v2/c0797faf2840116ac797065a51d101ad   <none>              f562bf3857f9        2 days ago          54.5MB                    
registry2.balena-cloud.com/v2/db91f2af7ef5170e08a3aa2cd509d83f   <none>              31edb96344b8        2 days ago          139MB                     
balena/amd64-supervisor                                          v10.2.2             326aafd36af4        3 months ago        49.5MB                    
hello-world                                                      latest              fce289e99eb9        11 months ago       1.84kB

Is it possible to inspect the actual layers that are persisted on the device and display their sizes?

Tnx
Bruno

Hi Bruno

command balena history <IMAGE ID> will provide the list of layers as well as their sizes

Cheers

federico

Hi Federico,

I get something like this:

root@f14c40f:~# balena-engine history 2d99eb6d7129
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
2d99eb6d7129        2 days ago          /bin/sh -c #(nop)  CMD ["python3" "./compres…   0B                  
<missing>           2 days ago          /bin/sh -c #(nop) COPY file:86d30a247e873244…   2.02kB              
<missing>           2 days ago          /bin/sh -c install_packages lame python3 && …   52MB                
<missing>           2 days ago          /bin/sh -c #(nop) COPY file:23cd687ba511edbd…   194kB               
<missing>           12 days ago         /bin/sh -c curl -SLO "https://raw.githubuser…   0B                  
<missing>           12 days ago         /bin/sh -c #(nop)  ENTRYPOINT ["/usr/bin/ent…   0B                  
<missing>           12 days ago         /bin/sh -c #(nop) COPY file:182ce03eab3864ad…   1.54kB              
<missing>           12 days ago         /bin/sh -c #(nop)  ENV UDEV=off                 0B                  
<missing>           12 days ago         /bin/sh -c curl -SLO "http://resin-packages.…   1.62MB              
<missing>           12 days ago         /bin/sh -c apk add --no-cache   bash   ca-ce…   28.1MB              
<missing>           12 days ago         /bin/sh -c #(nop)  LABEL io.balena.architect…   0B                  
<missing>           6 weeks ago         /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B                  
<missing>           6 weeks ago         /bin/sh -c #(nop) ADD file:fe1f09249227e2da2…   5.55MB

What does the label tell me? I thought each layer on my device had its own id.

Tnx
Bruno

Hey Bruno

yes, it makes sense: if you sum the values in the SIZE column you’ll get a number close to that 87.5MB that images reported

cheers

federico

For the record, another way to look at what makes an image is docker inspect <IMAGEID>. It will print a json document with a RootFS key that will list the images overlays

cheers

federico

I did that for two of my application images, getting the following results in the json:

"RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:77cae8ab23bf486355d1b3191259705374f4a11d483b24964d2f729dd8c076a0",
                "sha256:26db6b77ba50af49be09d25309019e65006551cee1107da1e5efc5405e7a319e",
                "sha256:e6b43765c5b2a633d408bed35d0dbeb01e38494cd582bc43c85116db73c5a8ba",
                "sha256:4427b4542a0005e5b4c782305ea1b4be56c075318ca62da995ec69c7ddf95017",
                "sha256:0da85665fcd32b7cf094d2202eebe2023cbf264dc02905b4397c9e845b823473",
                "sha256:986c357479ad0a187aab4b82c7f16d0f09ec23e1218490c9498bd1fa10a2829d"
            ]
        }

and

"RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:77cae8ab23bf486355d1b3191259705374f4a11d483b24964d2f729dd8c076a0",
                "sha256:26db6b77ba50af49be09d25309019e65006551cee1107da1e5efc5405e7a319e",
                "sha256:e6b43765c5b2a633d408bed35d0dbeb01e38494cd582bc43c85116db73c5a8ba",
                "sha256:4427b4542a0005e5b4c782305ea1b4be56c075318ca62da995ec69c7ddf95017",
                "sha256:05f8712f3a0a90c04ad75a3c2511f5ce95ecb87b1f2cabd6dd8910566a3f3e0c",
                "sha256:b4b73ea68a488ad208d73161d1910c48dd44a9a960914e012ae36d1f70620f4b",
                "sha256:68a8a09189c1862d554bc75af796215c89acaba7bbc11ca5b5e027af577d081f"
            ]
        }

Is my understanding correct?

  1. The first 4 layers are used by both images.
  2. The other layers are different
  3. The first 4 layers are stored only once in my devices filesystem, although their size contributes to both total image sizes displayed in the balenaCloud releases tab.

Thanks
Bruno

Hi there,

This is absolutely correct, the first 4 layers will only appear once in the filing system and will be shared by both of the images.

You’re also correct in the assertion that the image size shown for both images is the total for all layers. balenaEngine (and Docker), only request the layers that are not already present on a device when an application update occurs, thus minimising the amount of data transferred. However, there are even more savings to be had, and we also offer Delta updates for images as well (see here for more information on deltas).

Best regards,

Heds

Hello Balena team. Great support again, chapeau.
Bruno

You’re most welcome! Please let us know if you have any other questions in the future!

Best regards,

Heds