genuinetools / img

Standalone, daemon-less, unprivileged Dockerfile and OCI compatible container image builder.
https://blog.jessfraz.com/post/building-container-images-securely-on-kubernetes/
MIT License
3.9k stars 231 forks source link

ADD tar-Archive fails with ""/" is not an img command" #293

Open WolleTD opened 4 years ago

WolleTD commented 4 years ago

When trying to add a tar archive to an image, the build fails with this confusing error and the img usage text.

...
#4 [1/1] ADD test.tar /test
#4 ERROR: Error processing tar file(exit status 1): Error: img: '/' is not an img command.
See 'img --help'
img -  Standalone, daemon-less, unprivileged Dockerfile and OCI compatible container image builder

Usage: img [OPTIONS] COMMAND [ARG...]
...

Steps to reproduce

echo -e "FROM scratch\nADD test.tar /test" > Dockerfile
tar cf test.tar Dockerfile
img build . -t test

Version info

img:
 version     : v0.5.10
 git hash    : 38b683a6
 go version  : go1.14.3
 go compiler : gc
 platform    : linux/amd64
runc:
 version     : 1.0.0-rc10
 commit      : dc9208a3303feef5b3839f4323d9beb36df0a9dd
 spec        : 1.0.1-dev

Built with https://aur.archlinux.org/packages/img-git/

WolleTD commented 4 years ago

I'm not a Go developer, but upon further investigation, I managed to understand the cause. Unpacking a tar file depends on calling dockers own reexec-Module right at the beginning of main(): https://github.com/docker/docker-ce/blob/fe40dc7ec9f34021fcf6561b1d69608bc05d6329/components/engine/cmd/dockerd/docker.go#L72

This hack at least allows unpacking a tar as root, but somehow img's own, userns-aware reexec has to be plumbed into this... https://github.com/WolleTD/img/commit/6a47aae0a43274050aac9913b9034132dc53097a

mxmorin commented 3 years ago

Same problem with a local tar.gz

Url as source is working but not with a local tar or tar.gz.