Standalone, daemon-less, unprivileged Dockerfile and OCI compatible container image builder.
Standalone, daemon-less, unprivileged Dockerfile and OCI compatible container image builder.
Standalone, daemon-less, unprivileged Dockerfile and OCI compatible container image builder.
img is more cache-efficient than Docker and can also execute multiple build stages concurrently,
as it internally uses BuildKit's DAG solver.
The commands/UX are the same as docker {build,tag,push,pull,login,logout,save} so all you
have to do is replace docker with img in your scripts, command line, and/or life.
Table of Contents
This a glorified cli tool built on top of buildkit. The goal of this project is to be able to build container images as an unprivileged user.
Running unprivileged allows companies who use LDAP and other login mechanisms
to use img without needing root. This is very important in HPC environments
and academia as well.
Currently this works out of the box on a Linux machine if you install via
the directions covered in installing from binaries. This
installation will ensure you have the correct version of img and also runc.
The ultimate goal is to also have this work inside a container. There are patches being made to container runtimes and Kubernetes to make this possible. For the on-going work toward getting patches into container runtimes and Kubernetes, see:
The patches for runc has been merged into the upstream since ecd55a4135e0a26de884ce436442914f945b1e76 (May 30, 2018).
The upstream BuildKit can also run in rootless mode since 65b526438b86a17cf35042011051ce15c8bfb92a (June 1, 2018).
You might also be interested in reading:
If you are curious about benchmarks comparing various container builders, check out @AkihiroSuda's buildbench results.
You need to have newuidmap installed. On Ubuntu, newuidmap is provided by the uidmap package.
You also need to have seccomp installed. On Ubuntu, seccomp is provided by the libseccomp-dev package.
runc will be installed on start from an embedded binary if it is not already
available locally. If you would like to disable the embedded runc you can use BUILDTAGS="seccomp noembed" while building from source with make. Or the environment variable
IMG_DISABLE_EMBEDDED_RUNC=1 on execution of the img binary.
NOTE: These steps work only for Linux. Compile and run in a container (explained below) if you're on Windows or MacOS.
For installation instructions from binaries please visit the Releases Page.
$ mkdir -p $GOPATH/src/github.com/genuinetools
$ git clone https://github.com/genuinetools/img $GOPATH/src/github.com/genuinetools/img
$ cd !$
$ make
$ sudo make install
# For packagers if you would like to disable the embedded `runc`, please use:
$ make BUILDTAGS="seccomp noembed"There is an APKBUILD.
$ apk add imgThere is an AUR build.
# Use whichever AUR helper you prefer
$ yay -S img
# Or build from the source PKGBUILD
$ git clone https://aur.archlinux.org/packages/img.git
$ cd img
$ makepkg -siThere is an ebuild.
$ sudo emerge -a app-emulation/imgDocker image r.j3ss.co/img is configured to be executed as an unprivileged user with UID 1000 and it does not need --privileged since img v0.5.11.
$ docker run --rm -it \
--name img \
--volume $(pwd):/home/user/src:ro \ # for the build context and dockerfile, can be read-only since we won't modify it
--workdir /home/user/src \ # set the builder working directory
--volume "${HOME}/.docker:/root/.docker:ro" \ # for credentials to push to docker hub or a registry
--security-opt seccomp=unconfined --security-opt apparmor=unconfined \ # required by runc
r.j3ss.co/img build -t user/myimage .To enable PID namespace isolation (which disallows build containers to kill(2) the img process), you need to specify
--privileged so that build containers can mount /proc with unshared PID namespaces.
Note that even with --privileged, img works as an unprivileged user with UID 1000.
See docker/cli patch for how to allow mounting /proc without --privileged.
Since img v0.5.11, you don't need to specify any securityContext for running img as a Kubernetes container.
However the following security annotations are needed:
container.apparmor.security.beta.kubernetes.io/img: unconfined
container.seccomp.security.alpha.kubernetes.io/img: unconfinedTo enable PID namespace isolation, you need to set securityContext.procMount to Unmasked (or simply set
securityContext.privileged to true).
securityContext.procMount is available since Kubernetes 1.12 with Docker 18.06/containerd 1.2/CRI-O 1.12.
Make sure you have user namespace support enabled. On some distros (Debian and
Arch Linux) this requires running echo 1 > /proc/sys/kernel/unprivileged_userns_clone.
……Use just like you would docker build.
…img and the underlying buildkit library support building containers for arbitrary platforms (OS and architecture combinations). In img this can be achieved using the --platform option, but note that
using the RUN command during a build requires installing support for the desired platform, and any FROM images used must exist for the target platform as well.
Some common platforms include:
If you use multiple --platform options for the same build, they will be included into a manifest and should work for the different platforms built for.
The most common way to get RUN working in cross-platform builds is to install an emulator such as QEMU on the host system (static bindings are recommended to avoid shared library loading issues). To properly use the emulator inside the build environment, the kernel binfmt_misc parameters must be set with the following flags: OCF.
You can check the settings in /proc to ensure they are set correctly.
$ cat /proc/sys/fs/binfmt_misc/qemu-arm | grep flags
flags: OCFOn Debian/Ubuntu the above should be available with the qemu-user-static package >= 1:2.12+dfsg-3
NOTE: cross-OS builds are slightly more complicated to get RUN commands working, but follow from the same principle.
img can also use buildkit's exporter types directly to output the
resulting image to a Docker-type bundle or a rootfs tar without saving the image
itself locally. Builds will still benefit from caching.
The output type and destination are specified with the --output flag. The list
of valid output specifications includes:
| flag | description |
|---|---|
-o type=tar,dest=rootfs.tar |
export rootfs of target image to a tar archive |
-o type=tar |
output a rootfs tar to stdout, for use in piped commands |
-o type=docker,dest=image.tar |
save a Docker-type bundle of the image |
-o type=oci,dest=image.tar |
save an OCI-type bundle of the image |
-o type=local,dest=rootfs/ |
export the target image to this directory |
-o type=image,name=r.j3ss.co/img |
build and tag an image and store it locally |
When used in conjunction with a Dockerfile which has a final FROM scratch stage and
only copies files of interest from earlier stages with COPY --from=..., this can be
utilized to output arbitrary build artifacts for example.
$ img ls -h
ls - List images and digests.
Usage: img ls [OPTIONS]
Flags:
-f, --filter list Filter output based on conditions provided
-h, --help help for ls
Global Flags:
-b, --backend string backend for snapshots ([auto native overlayfs fuse-overlayfs]) (default "auto")
-d, --debug enable debug logging
-s, --state string directory to hold the global state (default "/home/user/.local/share/img")$ img ls
NAME SIZE CREATED AT UPDATED AT DIGEST
jess/img:latest 1.534KiB 9 seconds ago 9 seconds ago sha256:27d862ac32022946d61afbb91ddfc6a1fa2341a78a0da11ff9595a85f651d51e
jess/thing:latest 591B 30 minutes ago 30 minutes ago sha256:d664b4e9b9cd8b3067e122ef68180e95dd4494fd4cb01d05632b6e77ce19118eIf you need to use self-signed certs with your registry, see Using Self-Signed Certs with a Registry.
$ img pull -h
pull - Pull an image or a repository from a registry.
Usage: img pull [OPTIONS] NAME[:TAG|@DIGEST]
Flags:
-h, --help help for pull
Global Flags:
-b, --backend string backend for snapshots ([auto native overlayfs fuse-overlayfs]) (default "auto")
-d, --debug enable debug logging
-s, --state string directory to hold the global state (default "/home/user/.local/share/img")$ img pull r.j3ss.co/stress
Pulling r.j3ss.co/stress:latest...
Snapshot ref: sha256:2bb7a0a5f074ffe898b1ef64b3761e7f5062c3bdfe9947960e6db48a998ae1d6
Size: 365.9KiB
`No open issues yet, or sync has not completed.