container icon indicating copy to clipboard operation
container copied to clipboard

Very slow build time compared to Docker for Mac

Open outcoldman opened this issue 1 year ago • 8 comments

Just out of curiosity, I tried to build container cli and run it. (macOS 26 on MBA M2).

I have an enterprise software that I package in the docker image, it is ~5GB image.

On Docker for Mac it takes about 3-4 minutes to build.

With container it takes 17 minutes :(

Specifically it takes forever to run those steps:

 => exporting to oci image format                                                                                                                                          168.3s
 => => exporting layers                                                                                                                                                    147.3s
 => => exporting manifest sha256:c588472a6181c73404c412ba128eea840598578191be4b6631f5794a6107b6f3                                                                            0.0s
 => => exporting config sha256:0f34010f259e1c8140d3c7cdd81d0ada30fc8a9a95f20ae0bd056dad9fe01fd3                                                                              0.0s
 => => exporting manifest list sha256:963f1440f2064899e331f4b4e568a0693a08a639c8c907f52c34748b39bd027b                                                                       0.0s
 => => sending tarball                                                                                                                                                      20.9s
⠸ Unpacking built image for platform linux/amd64 (67.5 MB, 2.0 MB/s) [14s]  

I am still waiting for the unpacking step.

So the last command still runs

⠹ Unpacking built image for platform linux/amd64 (2.47 GB, 370 KB/s) [6m 37s]  

outcoldman avatar Jun 09 '25 23:06 outcoldman

Could you verify that you are running a release build? You can do this by running

container --version

If you aren't on a release build - you can do so by running make release. A release build will give you significant speed ups in image unpacks

adityaramani avatar Jun 10 '25 00:06 adityaramani

It used to be debug, so I have changed it to release but issue is still there.

I have an example that you can use to try: https://github.com/outcoldman/docker-splunk/tree/master/enterprise, it is pretty simple Dockerfile, that downloads Splunk and puts it in the container.

With Docker

time docker build --platform linux/amd64  -t splunk:latest .
[+] Building 178.6s (14/14) FINISHED                                                                                                                                               docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                               0.0s
 => => transferring dockerfile: 2.58kB                                                                                                                                                             0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                                                                   0.7s
 => [auth] library/ubuntu:pull token for registry-1.docker.io                                                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                                                                                  0.0s
 => => transferring context: 2B                                                                                                                                                                    0.0s
 => CACHED [1/8] FROM docker.io/library/ubuntu:latest@sha256:b59d21599a2b151e23eea5f6602f4af4d7d31c4e236d22bf0b62b86d2e386b8f                                                                      0.0s
 => [internal] load build context                                                                                                                                                                  0.0s
 => => transferring context: 35B                                                                                                                                                                   0.0s
 => [2/8] RUN groupadd -r splunk     && useradd -r -m -g splunk splunk                                                                                                                             0.2s
 => [3/8] RUN apt-get update  && apt-get install -y --no-install-recommends apt-utils && apt-get install -y locales && rm -rf /var/lib/apt/lists/*  && localedef -i en_US -c -f UTF-8 -A /usr/sh  23.2s
 => [4/8] RUN apt-get update && apt-get install -y libgssapi-krb5-2 && rm -rf /var/lib/apt/lists/*                                                                                                 7.9s 
 => [5/8] RUN apt-get update && apt-get install -y wget sudo     && mkdir -p /opt/splunk     && wget -qO /tmp/splunk-9.4.1-e3bdab203ac8-linux-amd64.tgz https://download.splunk.com/products/sp  134.0s 
 => [6/8] COPY entrypoint.sh /sbin/entrypoint.sh                                                                                                                                                   0.1s 
 => [7/8] RUN chmod +x /sbin/entrypoint.sh                                                                                                                                                         0.3s 
 => [8/8] WORKDIR /opt/splunk                                                                                                                                                                      0.0s 
 => exporting to image                                                                                                                                                                            12.0s 
 => => exporting layers                                                                                                                                                                           11.9s 
 => => writing image sha256:f9912528ecc3f9738785d1d113f92e1a6e7dbe50f5c1769643f0a2564de2976c                                                                                                       0.0s 
 => => naming to docker.io/library/splunk:latest                                                                                                                                                   0.0s

View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/tt5oe89d5r7bgo09391l9oqi2

 9 warnings found (use docker --debug to expand):
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 8)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 21)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 3)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 9)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 10)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 11)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 4)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 5)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 6)

What's next:
    View a summary of image vulnerabilities and recommendations → docker scout quickview 
docker build --platform linux/amd64 -t splunk:latest .  0.57s user 0.62s system 0% cpu 2:59.15 total

So took about 3 minutes.

With container

container --version
container CLI version 0.1.0 (build: release, commit: 0fd8692)

The builder I use

container builder status                     
ID       IMAGE                           STATE   ADDR         CPUS MEMORY
buildkit ghcr.io/apple/container-builder-shim/builder:0.1.0 RUNNING  4    8192 MB

And the build time... still building 1519 seconds...

time container build --arch amd64 -t splunk:latest .                                                                                                                                                                            
[+] Building 1519.4s (7/11)                                                                                                                                                                             
 => [resolver] fetching image...docker.io/library/ubuntu                                                                                                                                           0.0s
 => [internal] load .dockerignore                                                                                                                                                                  0.1s
 => => transferring context: 2B                                                                                                                                                                    0.0s
 => [linux/amd64 1/8] FROM docker.io/library/ubuntu:latest@sha256:b59d21599a2b151e23eea5f6602f4af4d7d31c4e236d22bf0b62b86d2e386b8f                                                                 5.0s
 => => resolve docker.io/library/ubuntu:latest@sha256:b59d21599a2b151e23eea5f6602f4af4d7d31c4e236d22bf0b62b86d2e386b8f                                                                             1.0s
 => => sha256:d9d352c11bbd3880007953ed6eec1cbace76898828f3434984a0ca60672fdf5a 29.72MB / 29.72MB                                                                                                   3.4s
 => => extracting sha256:d9d352c11bbd3880007953ed6eec1cbace76898828f3434984a0ca60672fdf5a                                                                                                          0.5s
 => [internal] load build context                                                                                                                                                                  0.1s
 => => transferring context: 5.98kB                                                                                                                                                                0.0s
 => [linux/amd64 2/8] RUN groupadd -r splunk     && useradd -r -m -g splunk splunk                                                                                                                 9.5s 
 => [linux/amd64 3/8] RUN apt-get update  && apt-get install -y --no-install-recommends apt-utils && apt-get install -y locales && rm -rf /var/lib/apt/lists/*  && localedef -i en_US -c -f UTF-  51.9s 
 => [linux/amd64 4/8] RUN apt-get update && apt-get install -y libgssapi-krb5-2 && rm -rf /var/lib/apt/lists/*                                                                                    27.6s 
 => [linux/amd64 5/8] RUN apt-get update && apt-get install -y wget sudo     && mkdir -p /opt/splunk     && wget -qO /tmp/splunk-9.4.1-e3bdab203ac8-linux-amd64.tgz https://download.splunk.co  1424.7s 
 => => # Removing wget (1.21.4-1ubuntu4.1) ...                                                                                                                                                          
 => => # Removing libpsl5t64:amd64 (0.21.2-1.1build1) ...                                                                                                                                               
 => => # Removing publicsuffix (20231001.0357-0.1) ...                                                                                                                                                  
 => => # Processing triggers for libc-bin (2.39-0ubuntu8.4) ...                                                                                                                                        
 => => # (Reading database ... 5643 files and directories currently installed.)                                                                                                                        
 => => # Purging configuration files for wget (1.21.4-1ubuntu4.1) ...                                                                                                                                  

I feel like there is some issue about the file system. My guess a lot of files are being deleted. It just got stuck on the purging configuration files for wget...

outcoldman avatar Jun 10 '25 02:06 outcoldman

It looks like your builder is using additional CPUs and memory, although one issue that I hit (vs docker CLI) is the defaults for CPU and memory were much lower than what I had Docker Desktop configured to:

https://github.com/apple/container/blob/e3cc50746cd78b428f1b46e8b70141e9b55bd911/Sources/ContainerClient/Core/ContainerConfiguration.swift#L68-L75

In Docker Desktop you specify CPU+memory configuration for the top-level VM. With Apple container run and container build they are arguments: --cpus + --memory per container.

babldev avatar Jun 11 '25 18:06 babldev

Yeah, I did increase the builder, because that is something I also noticed very quickly, that the CPU and Memory were limited. But did not helped much. I do believe it is IO issue. Because that container would have a lot of files, and a lot of files need to be untar.

outcoldman avatar Jun 11 '25 21:06 outcoldman

Just a quick update, tried to use the latest container 0.5 and compare it again.

container builder status                                                                                                                           
ID        IMAGE                                               STATE    ADDR          CPUS  MEMORY
buildkit  ghcr.io/apple/container-builder-shim/builder:0.6.1  running  192.168.64.2  8     16384 MB

On Docker - ~90 seconds, on container ~182 seconds.

So about twice slower. But better in general.

container --version
container CLI version 0.5.0 (build: release, commit: 48230f3)

outcoldman avatar Oct 06 '25 12:10 outcoldman

@outcoldman Thanks for checking back in on this one from time to time and for the updates. It's nice to have a record of runs in the issue.

We found a rather glaring problem in the build stuff this week where we saw that buildkit was running steps via buildkit-qemu-emulator-x86_64 for amd64 builds even though we had thought everything was configured to use Rosetta for Linux. After merging apple/container-builder-shim#50 and #858, we should get faster and more reliable builds.

Please try out main, or the next release, and post your results for the same build. If the actual build time looks better than 182 seconds now, perhaps we can rename this issue so that it calls out the slow build performance aspect specifically.

I think then we should create a new issue (if we don't already have another) for the work to improve unpack performance, as we haven't yet focused on optimizing write performance for the SwiftEXT4 library.

jglogan avatar Nov 06 '25 23:11 jglogan

Hi @outcoldman, revisiting this issue, with apple/container#378 a while back we sped up unpack times.

I tried this on hotel wifi last night and the build took 16.5 minutes, but most of the that was due to the slow network. Here's what I got on the work wifi with a brand new builder and nothing in container's image store:

% time container build --platform linux/amd64  -t splunk:latest .
[+] Building 251.2s (12/12) FINISHED                                                                                                                                                                            
 => [resolver] fetching image...docker.io/library/ubuntu                                                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                                                                          0.0s
 => => transferring context: 2B                                                                                                                                                                            0.0s
 => oci-layout://docker.io/library/ubuntu@sha256:c35e29c9450151419d9448b0fd75374fec4fff364a27f176fb458d472dfc9e54                                                                                          1.0s
 => => resolve docker.io/library/ubuntu@sha256:c35e29c9450151419d9448b0fd75374fec4fff364a27f176fb458d472dfc9e54                                                                                            0.3s
 => => sha256:20043066d3d5c78b45520c5707319835ac7d1f3d7f0dded0138ea0897d6a3188 29.72MB / 29.72MB                                                                                                           0.3s
 => => extracting sha256:20043066d3d5c78b45520c5707319835ac7d1f3d7f0dded0138ea0897d6a3188                                                                                                                  0.4s
 => [internal] load build context                                                                                                                                                                          0.0s
 => => transferring context: 5.98kB                                                                                                                                                                        0.0s
 => [linux/amd64 1/8] RUN groupadd -r splunk     && useradd -r -m -g splunk splunk                                                                                                                         0.3s
 => [linux/amd64 2/8] RUN apt-get update  && apt-get install -y --no-install-recommends apt-utils && apt-get install -y locales && rm -rf /var/lib/apt/lists/*  && localedef -i en_US -c -f UTF-8 -A /us  30.9s
 => [linux/amd64 3/8] RUN apt-get update && apt-get install -y libgssapi-krb5-2 && rm -rf /var/lib/apt/lists/*                                                                                            10.2s 
 => [linux/amd64 4/8] RUN apt-get update && apt-get install -y wget sudo     && mkdir -p /opt/splunk     && wget -qO /tmp/splunk-9.4.1-e3bdab203ac8-linux-amd64.tgz https://download.splunk.com/product  141.0s 
 => [linux/amd64 5/8] COPY entrypoint.sh /sbin/entrypoint.sh                                                                                                                                               0.1s 
 => [linux/amd64 6/8] RUN chmod +x /sbin/entrypoint.sh                                                                                                                                                     0.1s 
 => [linux/amd64 7/8] WORKDIR /opt/splunk                                                                                                                                                                  0.0s 
 => exporting to oci image format                                                                                                                                                                         67.2s 
 => => exporting layers                                                                                                                                                                                   60.4s 
 => => exporting manifest sha256:3aaeb60799aa616da9d4acfeac0077bece0ead0c4becb90f06e5f2468e21c10f                                                                                                          0.0s 
 => => exporting config sha256:8f9f14cf5b4b002856ed666fda6ac84f15dd5257f17327ffcf11a2eca52fc3ba                                                                                                            0.0s
 => => exporting manifest list sha256:5c4b684b1f6a43fc6a4ac2870c7622e5cabd6424c7734ecbe6bf5e0c277ddb85                                                                                                     0.0s
 => => sending tarball                                                                                                                                                                                     6.8s
Successfully built splunk:latest
container build --platform linux/amd64 -t splunk:latest .  9.60s user 8.23s system 6% cpu 4:19.75 total

Colima on my system has comparable performance:

% time docker build --platform linux/amd64  -t splunk:latest .
[+] Building 295.3s (13/13) FINISHED                                                                                                                                                              docker:colima
 => [internal] load build definition from Dockerfile                                                                                                                                                       0.0s
 => => transferring dockerfile: 2.58kB                                                                                                                                                                     0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                                                                           1.5s
 => [internal] load .dockerignore                                                                                                                                                                          0.0s
 => => transferring context: 2B                                                                                                                                                                            0.0s
 => [1/8] FROM docker.io/library/ubuntu:latest@sha256:c35e29c9450151419d9448b0fd75374fec4fff364a27f176fb458d472dfc9e54                                                                                     2.6s
 => => resolve docker.io/library/ubuntu:latest@sha256:c35e29c9450151419d9448b0fd75374fec4fff364a27f176fb458d472dfc9e54                                                                                     0.2s
 => => sha256:20043066d3d5c78b45520c5707319835ac7d1f3d7f0dded0138ea0897d6a3188 29.72MB / 29.72MB                                                                                                           2.0s
 => => extracting sha256:20043066d3d5c78b45520c5707319835ac7d1f3d7f0dded0138ea0897d6a3188                                                                                                                  0.3s
 => [internal] load build context                                                                                                                                                                          0.0s
 => => transferring context: 5.98kB                                                                                                                                                                        0.0s
 => [2/8] RUN groupadd -r splunk     && useradd -r -m -g splunk splunk                                                                                                                                     0.2s
 => [3/8] RUN apt-get update  && apt-get install -y --no-install-recommends apt-utils && apt-get install -y locales && rm -rf /var/lib/apt/lists/*  && localedef -i en_US -c -f UTF-8 -A /usr/share/loca  37.2s
 => [4/8] RUN apt-get update && apt-get install -y libgssapi-krb5-2 && rm -rf /var/lib/apt/lists/*                                                                                                        22.7s 
 => [5/8] RUN apt-get update && apt-get install -y wget sudo     && mkdir -p /opt/splunk     && wget -qO /tmp/splunk-9.4.1-e3bdab203ac8-linux-amd64.tgz https://download.splunk.com/products/splunk/rel  162.6s 
 => [6/8] COPY entrypoint.sh /sbin/entrypoint.sh                                                                                                                                                           0.1s 
 => [7/8] RUN chmod +x /sbin/entrypoint.sh                                                                                                                                                                 0.1s 
 => [8/8] WORKDIR /opt/splunk                                                                                                                                                                              0.0s 
 => exporting to image                                                                                                                                                                                    68.1s 
 => => exporting layers                                                                                                                                                                                   68.1s 
 => => exporting manifest sha256:2d9ce35eec77908b758cad12062d5406b1c9702a7a06523bd6ff6b46dd5f9490                                                                                                          0.0s 
 => => exporting config sha256:4042b6764258f9dd72e1076de1993efd6142d4542b2e2a7affb9f85ed6a4e045                                                                                                            0.0s
 => => exporting attestation manifest sha256:e007004f9ff0a18c01a4a2a066ae0fe80d82a3fc76203602adc990ca5e4a7fd4                                                                                              0.0s
 => => exporting manifest list sha256:8f621da087817f3c164c0c990e5109ff003b057500910cb44f6afc10c12b003a                                                                                                     0.0s
 => => naming to docker.io/library/splunk:latest                                                                                                                                                           0.0s

 9 warnings found (use docker --debug to expand):
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 9)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 10)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 3)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 4)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 6)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 11)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 21)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 5)
 - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 8)
docker build --platform linux/amd64 -t splunk:latest .  0.39s user 0.51s system 0% cpu 4:55.67 total
/Users/john/Documents/sandboxes/20260113-container-68/docker-splunk/enterprise master kind-kind % 

jglogan avatar Jan 13 '26 18:01 jglogan

I'm going to close this as while build/unpack times are still a bit slower compared to Docker, they're not very slow. Feel free to open another issue for cases requiring further optimization.

jglogan avatar Jan 13 '26 18:01 jglogan