Build a Docker Container Image¶
KIWI NG is capable of building native Docker images, from scratch and derived ones. KIWI NG Docker images are considered to be native since the KIWI NG tarball image is ready to be loaded to a Docker daemon, including common container configurations.
The Docker configuration metadata is provided to KIWI NG as part of the
XML description file using the
<containerconfig> tag. The following configuration metadata can be
name: Specifies the repository name of the Docker image.
tag: Sets the tag of the Docker image.
maintainer: Specifies the author field of the container.
user: Sets the user name or user id (UID) to be used when running
subcommand. Equivalent of the
USERdirective of a Docker file.
workingdir: Sets the working directory to be used when running
entrypoint. Equivalent of the
WORKDIRdirective of a Docker file.
containerconfig child tags:
subcommand: Provides the default execution parameters of the container. Equivalent of the
CMDdirective of a Docker file.
labels: Adds custom metadata to an image using key-value pairs. Equivalent to one or more
LABELdirectives of a Docker file.
expose: Informs at which ports is the container listening at runtime. Equivalent to one or more
EXPOSEdirectives of a Docker file.
environment: Sets an environment values using key-value pairs. Equivalent to one or more the
envdirectives of a Docker file.
entrypoint: Sets the command that the container will run, it can include parameters. Equivalent of the
ENTRYPOINTdirective of a Docker file.
volumes: Create mountpoints with the given name and mark it to hold external volumes from the host or from other containers. Equivalent to one or more
VOLUMEdirectives of a Docker file.
The following example shows how to build a Docker base image based on openSUSE Leap:
Make sure you have checked out the example image descriptions, see Example Appliance Descriptions.
Virtualization/containersrepository to your list:
$ zypper addrepo http://download.opensuse.org/repositories/Virtualization:/containers/<DIST> container-tools
where the placeholder
<DIST>is the preferred distribution.
Install umoci and skopeo tools
$ zypper in umoci skopeo
Build the image with KIWI NG:
$ sudo kiwi-ng system build \ --description kiwi/build-tests/x86/leap/test-image-docker \ --set-repo obs://openSUSE:Leap:15.3/standard \ --target-dir /tmp/myimage
Test the Docker image.
First load the new image
$ docker load -i kiwi-test-image-docker.x86_64-1.15.3.docker.tar.xz
then run the loaded image:
$ docker run -it buildsystem /bin/bash