Multi-platform image size doubles

Hi,

I followed this document and created a github workflow to build a multi-platform docker image for my dotnet8 project. Because dotnet compile does not support the QEMU approach. I also followed this document to do a cross-compilation.

After the build succeeded, I pulled the merged image to my machine and inspect the image size. The image size is about 480MB.

I also build the image with --platform=linux/amd64,linux/arm64 option on my machine directly, but the image size is only about 250MB, which is just a bit larger than a single-platform image.

So, I am wondering why these two images are so different in size?

Thanks

You’re looking at disk space taken rather than image size

Do docker images --tree (Available with Docker API v1.47, released recently)
This should list image platforms and show their actual size alongside the disk usage

1 Like

Thanks. With the --tree option, I got this output

docker images --tree mongo:latest                                                                                                                                                                                                                      
WARNING: This is an experimental feature. The output may change and shouldn't be depended on.

IMAGE          ID             DISK USAGE   CONTENT SIZE   USED
mongo:latest   9a5e0d0cf6de        646MB             0B       

The mongo image used 646MB space on my disk. But the content size is 0?? Well, it is an experimental feature, so it could be a bug.

It may be that you’re not using the containerd image store, enable it and run the command again

As for checking the content size without it enabled, you can do docker inspect [image], and it’ll be in pute bytes as the “Size” property within the outputted JSON

Thanks a lot. This one looks much better.

➜  docker-services git:(local) docker images --tree
WARNING: This is an experimental feature. The output may change and shouldn't be depended on.

IMAGE                                  ID             DISK USAGE   CONTENT SIZE   USED
portainer/portainer-ce:2.20.1-alpine   78c026175e15        390MB         95.5MB    ✔
├─ linux/amd64                         78a246928b2a        390MB         95.5MB    ✔
├─ linux/arm/v7                        c2d07a4b21fa           0B             0B
└─ linux/arm64                         3a650c4cc285           0B             0B

So the content size is the compressed image size, right? The disk usage is the disk space used when I run an instance of the container. If I run multiple instances of the same image, will it cost multiple times the disk usage size of space?

Yes, that is exactly correct :slight_smile:

1 Like

It shouldn’t be the case. The overlay2 storage driver uses the image layers as read-only filesystem and mounts a container filesystem on top of it which is writable. So even if you run 100 containers from the same image, it should not multiply the disk usage.

To be honest I think I never used this --tree flag. Maybe only when it was first introduced, but I’m not sure what the content size is. I would expect it to be sum of the filesizes regardless of the filesystem which could affect disk usage, but when I run the command on my machines (Docker Desktop for Mac with arm cpu + Docker CE 27.3.1) All content sizes are zero and nothing is in the “USED” column even though I have multiple containers running.

@deanayalon Do I misunderstand the output?

It seem it is so experimental, I couldn’t find the column descriptions in the documentation yet.

Are you using the containerd image store? It seems to only show the content size with it enabled

1 Like

That was the problem :slight_smile: Now the output makes sense.