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?
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
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
â 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?
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.