Build a Container Image
KIWI NG can build native container images from scratch or using existing images. KIWI NG container images are considered native because a KIWI NG tarball image can be loaded directly into container runtimes like Podman, Docker, or Containerd, including common container configurations.
The container configuration metadata is supplied to KIWI NG as part of the
XML description file using the
<containerconfig> tag. The following configuration metadata can be
specified.
containerconfig attributes:
name: Specifies the repository name of the container image.tag: Sets the tag of the container image.maintainer: Specifies the author of the container. Equivalent to theMAINTAINERdirective in aDockerfile.user: Sets the user name or user id (UID) to be used when runningentrypointandsubcommand. Equivalent to theUSERdirective of aDockerfile.workingdir: Sets the working directory to be used when runningcmdandentrypoint. Equivalent to theWORKDIRdirective in aDockerfile.
containerconfig child tags:
subcommand: Provides the default execution parameters of the container. Equivalent to theCMDdirective in aDockerfile.labels: Adds custom metadata to an image using key-value pairs. Equivalent to one or moreLABELdirectives in aDockerfile.expose: Defines which ports can be exposed to the outside when running this container image. Equivalent to one or moreEXPOSEdirectives in aDockerfile.environment: Sets environment variables using key-value pairs. Equivalent to one or multipleENVdirectives in aDockerfile.entrypoint: Sets the binary to use for executing all commands inside the container. Equivalent to theENTRYPOINTdirective of aDockerfile.volumes: Creates mountpoints with the given name and marks them to hold external volumes from the host or from other containers. Equivalent to one or moreVOLUMEdirectives in aDockerfile.stopsignal: Thestopsignalelement sets the system call signal that will be sent to the container to exit. This signal can be a signal name in the formatSIG[NAME], for instance,SIGKILL, or an unsigned number that matches a position in the kernel’s syscall table, for instance, 9. The default isSIGTERMif not defined.
Other Dockerfile directives such as RUN, COPY, or ADD,
can be mapped to KIWI NG using the
config.sh script file to run Bash commands,
or the overlay tree to include
additional files.
The following example illustrates how to build a container image based on openSUSE Leap:
Make sure you have checked out the example image descriptions (see Example Appliance Descriptions).
Include the
Virtualization/containersrepository in your list (replace the placeholder<DIST>with the name of the desired distribution):$ zypper addrepo http://download.opensuse.org/repositories/Virtualization:/containers/<DIST> container-tools
Install
umociandskopeotools.$ zypper in umoci skopeo
Build an image with KIWI NG:
$ sudo kiwi-ng system build \ --description kiwi/build-tests/x86/leap/test-image-docker \ --set-repo https://download.opensuse.org/distribution/leap/15.6/repo/oss \ --target-dir /tmp/myimage
Test the container image.
First, load the new image into your container runtime:
$ podman load -i kiwi-test-image-docker.x86_64-1.15.6.docker.tar.xz
Then, run the image:
$ podman run --rm -it buildsystem /bin/bash