Debian Codegraph @

doc/source/example_use_cases/build_container_image.rst

raw
1 .. _building_container_build:
2
3 Build a Container Image
4 =======================
5
6 .. sidebar:: Abstract
7
8 This page explains how to build a Container Image. It covers the following topics:
9
10 * a basic configuration explanation
11 * how to build a Container Image
12 * how to run it with a Container Runtime
13
14 {kiwi} can build native container images from scratch or using existing images.
15 {kiwi} container images are considered native because a {kiwi} tarball
16 image can be loaded directly into container runtimes like Podman, Docker, or
17 Containerd, including common container configurations.
18
19 The container configuration metadata is supplied to {kiwi} as part of the
20 :ref:`XML description file <description_components>` using the
21 `<containerconfig>` tag. The following configuration metadata can be
22 specified.
23
24 `containerconfig` attributes:
25
26 * ``name``: Specifies the repository name of the container image.
27 * ``tag``: Sets the tag of the container image.
28 * ``additionalnames``: Additional fully qualified names for the image, given
29 as a comma-separated list of ``repository:tag`` entries. An entry that
30 starts with ``:`` adds another tag for the primary repository name, for
31 example ``:latest,:stable``.
32 This attribute is only applied to Docker archive output (`image="docker"`
33 or an OEM `format="docker:..."`); OCI archive output ignores it.
34 * ``maintainer``: Specifies the author of the container. Equivalent to the
35 `MAINTAINER` directive in a :file:`Dockerfile`.
36 * ``user``: Sets the user name or user id (UID) to be used when
37 running `entrypoint` and `subcommand`. Equivalent to the `USER`
38 directive of a :file:`Dockerfile`.
39 * ``workingdir``: Sets the working directory to be used when running
40 `cmd` and `entrypoint`. Equivalent to the `WORKDIR` directive in a
41 :file:`Dockerfile`.
42
43 `containerconfig` child tags:
44
45 * ``subcommand``: Provides the default execution parameters of the
46 container. Equivalent to the `CMD` directive in a :file:`Dockerfile`.
47 * ``labels``: Adds custom metadata to an image using key-value pairs.
48 Equivalent to one or more `LABEL` directives in a :file:`Dockerfile`.
49 * ``expose``: Defines which ports can be exposed to the outside when
50 running this container image. Equivalent to one or more `EXPOSE`
51 directives in a :file:`Dockerfile`.
52 * ``environment``: Sets environment variables using key-value pairs.
53 Equivalent to one or multiple `ENV` directives in a :file:`Dockerfile`.
54 * ``entrypoint``: Sets the binary to use for executing all commands inside the
55 container. Equivalent to the `ENTRYPOINT` directive of a :file:`Dockerfile`.
56 * ``volumes``: Creates mountpoints with the given name and marks them to hold
57 external volumes from the host or from other containers. Equivalent to
58 one or more `VOLUME` directives in a :file:`Dockerfile`.
59 * ``stopsignal``: The `stopsignal` element sets the system call signal that
60 will be sent to the container to exit. This signal can be a signal name
61 in the format `SIG[NAME]`, for instance, `SIGKILL`, or an unsigned number that
62 matches a position in the kernel's syscall table, for instance, 9.
63 The default is `SIGTERM` if not defined.
64
65 Other :file:`Dockerfile` directives such as `RUN`, `COPY`, or `ADD`,
66 can be mapped to {kiwi} using the
67 :ref:`config.sh <description_components>` script file to run Bash commands,
68 or the :ref:`overlay tree <description_components>` to include
69 additional files.
70
71 The following example illustrates how to build a container image based on
72 openSUSE Leap:
73
74 1. Install `umoci` and `skopeo` tools.
75
76 .. code:: bash
77
78 $ zypper in umoci skopeo
79
80 #. Build an image with {kiwi}:
81
82 .. code:: bash
83
84 $ sudo kiwi-ng system build \
85 --description kiwi/build-tests/{exc_description_docker} \
86 --set-repo {exc_repo_leap} \
87 --target-dir /tmp/myimage
88
89 #. Test the container image.
90
91 First, load the new image into your container runtime:
92
93 .. code:: bash
94
95 $ podman load -i {exc_image_base_name_docker}.x86_64-{exc_image_version}.docker.tar.xz
96
97 Then, run the image:
98
99 .. code:: bash
100
101 $ podman run --rm -it buildsystem /bin/bash