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

Question: how to use img in docker ? #336

Open warmanton opened 3 years ago

warmanton commented 3 years ago

Since Arch linux has no newuidmap and seccomp binaries (I did not found yet) I tried to use docker image of img. Used example from documentation

docker run -it --name img --volume $(pwd):/home/user/src:ro --workdir /home/user/src --volume "${HOME}/.docker:/root/.docker:ro" --security-opt seccomp=unconfined --security-opt apparmor=unconfined r.j3ss.co/img build -t test -f docker/myapp.Dockerfile .

It works but where then to find the image ? Container removed just after it finished to build the image. May be not enough examples in documentation. How to get image after building ? :-).

austonpramodh commented 3 years ago

Hi @warmanton, I am not sure if this is the right way to do it. You can build an image and output it to a tar file. Then you can use crane to push the tar file.

Build image and output it to tar file. docker run -it --name img --volume $(pwd):/home/user/src --workdir /home/user/src --security-opt seccomp=unconfined --security-opt apparmor=unconfined r.j3ss.co/img build -t test -o type=tar,dest=image.tar -f docker/myapp.Dockerfile .

Push the image to a registry docker run --rm --volume "$(pwd):/app" --entrypoint="sh" gcr.io/go-containerregistry/crane:debug sh -c "crane auth login -u $USERNAME -p $PASSWORD $REGISTRY && crane push /app/image.tar $REGISTRY/path/to/your/image:version"

I haven't tried it myself. Let me know if it works.

Reference: https://stackoverflow.com/questions/62665625/how-to-perform-kaniko-docker-build-and-push-in-separate-gitlab-ci-stages