Skip to content

[Bug]: container build --output type=tar produces empty files #347

@tamird

Description

@tamird

I have done the following

  • I have searched the existing issues
  • If possible, I've reproduced the issue using the 'main' branch of this project

Steps to reproduce

See Dockerfile, container output, and docker output below:

% ls
total 8
drwxr-xr-x   3 tamird  staff    96B Jul 17 01:51 .
drwxr-xr-x  14 tamird  staff   448B Jul 17 01:47 ..
-rw-r--r--   1 tamird  staff   141B Jul 17 01:49 Dockerfile
% cat Dockerfile
FROM busybox:latest AS build
RUN echo "hello from $(date -u +%FT%TZ)" > /hello.txt

FROM scratch AS artifact
COPY --from=build /hello.txt /

% container build . --target artifact --progress plain --output type=tar,dest=container-out
#1 [resolver] fetching image...docker.io/library/busybox:latest
#1 DONE 0.0s

#2 [resolver] fetching image...docker.io/library/scratch
#2 DONE 0.0s

#3 [internal] load .dockerignore
#3 transferring context: 2B 0.0s done
#3 DONE 0.0s

#4 oci-layout://docker.io/library/busybox:latest@sha256:f85340bf132ae937d2c2a763b8335c9bab35d6e8293f70f606b9c6178d84f42b
#4 resolve docker.io/library/busybox:latest@sha256:f85340bf132ae937d2c2a763b8335c9bab35d6e8293f70f606b9c6178d84f42b done
#4 DONE 0.0s

#5 [linux/arm64 build 1/2] RUN echo "hello from $(date -u +%FT%TZ)" > /hello.txt
#5 CACHED

#6 [linux/arm64/v8 artifact 1/1] COPY --from=build /hello.txt /
#6 CACHED

#7 exporting to client tarball
#7 sending tarball done
#7 DONE 0.0s
Successfully built b0664c8b-5859-4444-8e97-e1c3496bbd52:latest
% ls
total 8
drwxr-xr-x   4 tamird  staff   128B Jul 17 01:51 .
drwxr-xr-x  14 tamird  staff   448B Jul 17 01:47 ..
-rw-r--r--   1 tamird  staff     0B Jul 17 01:51 container-out
-rw-r--r--   1 tamird  staff   141B Jul 17 01:49 Dockerfile
% rm container-out
% docker buildx build . --target artifact --progress plain --output type=tar,dest=container-out
#0 building with "default" instance using docker-container driver

#1 [internal] booting buildkit
#1 starting container buildx_buildkit_default
#1 starting container buildx_buildkit_default 0.6s done
#1 DONE 0.6s

#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 180B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/busybox:latest
#3 DONE 0.5s

#4 [internal] load .dockerignore
#4 transferring context: 2B done
#4 DONE 0.0s

#5 [build 1/2] FROM docker.io/library/busybox:latest@sha256:f85340bf132ae937d2c2a763b8335c9bab35d6e8293f70f606b9c6178d84f42b
#5 resolve docker.io/library/busybox:latest@sha256:f85340bf132ae937d2c2a763b8335c9bab35d6e8293f70f606b9c6178d84f42b done
#5 sha256:189fdd1508372905e80cc3edcdb56cdc4fa216aebef6f332dd3cba6e300238ea 1.84MB / 1.84MB 0.1s done
#5 extracting sha256:189fdd1508372905e80cc3edcdb56cdc4fa216aebef6f332dd3cba6e300238ea 0.0s done
#5 DONE 0.2s

#6 [build 2/2] RUN echo "hello from $(date -u +%FT%TZ)" > /hello.txt
#6 DONE 0.1s

#7 [artifact 1/1] COPY --from=build /hello.txt /
#7 DONE 0.0s

#8 exporting to client tarball
#8 sending tarball done
#8 DONE 0.0s
% ls
total 16
drwxr-xr-x   4 tamird  staff   128B Jul 17 01:52 .
drwxr-xr-x  14 tamird  staff   448B Jul 17 01:47 ..
-rw-r--r--   1 tamird  staff   3.0K Jul 17 01:52 container-out
-rw-r--r--   1 tamird  staff   141B Jul 17 01:49 Dockerfile

Current behavior

output file has zero size.

% ls
total 8
drwxr-xr-x   4 tamird  staff   128B Jul 17 01:51 .
drwxr-xr-x  14 tamird  staff   448B Jul 17 01:47 ..
-rw-r--r--   1 tamird  staff     0B Jul 17 01:51 container-out
-rw-r--r--   1 tamird  staff   141B Jul 17 01:49 Dockerfile

Expected behavior

output file has nonzero size.

% ls
total 16
drwxr-xr-x   4 tamird  staff   128B Jul 17 01:52 .
drwxr-xr-x  14 tamird  staff   448B Jul 17 01:47 ..
-rw-r--r--   1 tamird  staff   3.0K Jul 17 01:52 container-out
-rw-r--r--   1 tamird  staff   141B Jul 17 01:49 Dockerfile

Environment

- OS: Darwin L03G26TD12 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:53:27 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6041 arm64
- Xcode: CLT
- Container: container CLI version 0.2.0 (build: release, commit: 3b5c253)

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions