Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 7. Adding software to a UBI container
Red Hat Universal Base Images (UBIs) are built from a subset of the RHEL content. UBIs also provide a subset of RHEL packages that are freely available to install for use with UBI. To add or update software to a running container, you can use the DNF repositories that include RPM packages and updates. UBIs provide a set of pre-built language runtime container images such as Python, Perl, Node.js, Ruby, and so on.
To add packages from UBI repositories to running UBI containers:
-
On UBI init and UBI standard images, use the
dnfcommand -
On UBI minimal images, use the
microdnfcommand
Installing and working with software packages directly in running containers adds packages temporarily. The changes are not saved in the container image. To make package changes persistent, see section Building an image from a Containerfile with Buildah.
7.1. Using the UBI init images Link kopierenLink in die Zwischenablage kopiert!
You can build a container by using a Containerfile that installs and configures a Web server (httpd) to start automatically by the systemd service (/sbin/init) when the container is run on a host system. The podman build command builds an image by using instructions in one or more Containerfiles and a specified build context directory. The context directory can be specified as the URL of an archive, Git repository or Containerfile. If no context directory is specified, then the current working directory is considered as the build context, and must contain the Containerfile. You can also specify a Containerfile with the --file option.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create a
Containerfilewith the following contents to a new directory:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
Containerfileinstalls thehttpdpackage, enables thehttpdservice to start at boot time, creates a test file (index.html), exposes the Web server to the host (port 80), and starts thesystemdinit service (/sbin/init) when the container starts.Build the container:
podman build --format=docker -t mysysd .
# podman build --format=docker -t mysysd .Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: If you want to run containers with
systemdand SELinux is enabled on your system, you must set thecontainer_manage_cgroupboolean variable:setsebool -P container_manage_cgroup 1
# setsebool -P container_manage_cgroup 1Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the container named
mysysd_run:podman run -d --name=mysysd_run -p 80:80 mysysd
# podman run -d --name=mysysd_run -p 80:80 mysysdCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
mysysdimage runs as themysysd_runcontainer as a daemon process, with port 80 from the container exposed to port 80 on the host system.NoteIn rootless mode, you have to choose host port number >= 1024. For example:
podman run -d --name=mysysd -p 8081:80 mysysd
$ podman run -d --name=mysysd -p 8081:80 mysysdCopy to Clipboard Copied! Toggle word wrap Toggle overflow To use port numbers < 1024, you have to modify the
net.ipv4.ip_unprivileged_port_startvariable:sysctl net.ipv4.ip_unprivileged_port_start=80
# sysctl net.ipv4.ip_unprivileged_port_start=80Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check that the container is running:
podman ps
# podman ps a282b0c2ad3d localhost/mysysd:latest /sbin/init 15 seconds ago Up 14 seconds ago 0.0.0.0:80->80/tcp mysysd_runCopy to Clipboard Copied! Toggle word wrap Toggle overflow Test the web server:
curl localhost/index.html
# curl localhost/index.html Successful Web Server TestCopy to Clipboard Copied! Toggle word wrap Toggle overflow
7.2. Using the UBI micro images Link kopierenLink in die Zwischenablage kopiert!
You can build a ubi-micro container image by using the Buildah tool.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Pull and build the
registry.access.redhat.com/ubi10/ubi-microimage:microcontainer=$(buildah from registry.access.redhat.com/ubi10/ubi-micro)
# microcontainer=$(buildah from registry.access.redhat.com/ubi10/ubi-micro)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Mount a working container root filesystem:
micromount=$(buildah mount $microcontainer)
# micromount=$(buildah mount $microcontainer)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Install the
httpdservice to themicromountdirectory:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Unmount the root file system on the working container:
buildah umount $microcontainer
# buildah umount $microcontainerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
ubi-micro-httpdimage from a working container:buildah commit $microcontainer ubi-micro-httpd
# buildah commit $microcontainer ubi-micro-httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Display details about the
ubi-micro-httpdimage:podman images ubi-micro-httpd
# podman images ubi-micro-httpd localhost/ubi-micro-httpd latest 7c557e7fbe9f 22 minutes ago 151 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow
7.3. Adding software to a UBI container on a subscribed host Link kopierenLink in die Zwischenablage kopiert!
If you are running a UBI container on a registered and subscribed RHEL host, the RHEL Base and AppStream repositories are enabled inside the standard UBI container, along with all the UBI repositories.
Red Hat entitlements are passed from a subscribed Red Hat host as a secrets mount defined in
/usr/share/containers/mounts.confon the host running Podman.Verify the mounts configuration:
cat /usr/share/containers/mounts.conf /usr/share/rhel/secrets:/run/secrets
$ cat /usr/share/containers/mounts.conf /usr/share/rhel/secrets:/run/secretsCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
yum,dnf, andmicrodnfcommands should search for entitlement data at this path. - If the path is not present, the commands cannot use Red Hat entitled content, such as the RHV repositories, because they lack the keys or content access the host has.
- This is applicable only for Red Hat shipped or provided Podman on a RHEL host.
- If you installed Podman not shipped by Red Hat, follow the instructions in How do I attach subscription data to containers running in Docker not provided by Red Hat? article.
7.4. Adding software in a standard UBI container Link kopierenLink in die Zwischenablage kopiert!
To add software inside the standard UBI container, disable non-UBI dnf repositories to ensure the containers you build can be redistributed.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Pull and run the
registry.access.redhat.com/ubi10/ubiimage:podman run -it --name myubi registry.access.redhat.com/ubi10/ubi
$ podman run -it --name myubi registry.access.redhat.com/ubi10/ubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add a package to the
myubicontainer.To add a package that is in the UBI repository, disable all dnf repositories except for UBI repositories. For example, to add the
bzip2package:dnf install --disablerepo=* --enablerepo=ubi-8-appstream-rpms --enablerepo=ubi-8-baseos-rpms bzip2
# dnf install --disablerepo=* --enablerepo=ubi-8-appstream-rpms --enablerepo=ubi-8-baseos-rpms bzip2Copy to Clipboard Copied! Toggle word wrap Toggle overflow To add a package that is not in the UBI repository, do not disable any repositories. For example, to add the
zshpackage:dnf install zsh
# dnf install zshCopy to Clipboard Copied! Toggle word wrap Toggle overflow To add a package that is in a different host repository, explicitly enable the repository you need. For example, to install the
python38-develpackage from thecodeready-builder-for-rhel-8-x86_64-rpmsrepository:dnf install --enablerepo=codeready-builder-for-rhel-8-x86_64-rpms python38-devel
# dnf install --enablerepo=codeready-builder-for-rhel-8-x86_64-rpms python38-develCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
List all enabled repositories inside the container:
dnf repolist
# dnf repolistCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Ensure that the required repositories are listed.
List all installed packages:
rpm -qa
# rpm -qaCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Ensure that the required packages are listed.
Installing Red Hat packages that are not inside the Red Hat UBI repositories can limit the ability to distribute the container outside of subscribed RHEL systems.
7.5. Adding software in a minimal UBI container Link kopierenLink in die Zwischenablage kopiert!
UBI dnf repositories are enabled inside UBI Minimal images by default.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Pull and run the
registry.access.redhat.com/ubi10/ubi-minimalimage:podman run -it --name myubimin registry.access.redhat.com/ubi10/ubi-minimal
$ podman run -it --name myubimin registry.access.redhat.com/ubi10/ubi-minimalCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add a package to the
myubimincontainer:To add a package that is in the UBI repository, do not disable any repositories. For example, to add the
bzip2package:microdnf install bzip2 --setopt install_weak_deps=false
# microdnf install bzip2 --setopt install_weak_deps=falseCopy to Clipboard Copied! Toggle word wrap Toggle overflow To add a package that is in a different host repository, explicitly enable the repository you need. For example, to install the
python38-develpackage from thecodeready-builder-for-rhel-8-x86_64-rpmsrepository:microdnf install --enablerepo=codeready-builder-for-rhel-8-x86_64-rpms python38-devel --setopt install_weak_deps=false
# microdnf install --enablerepo=codeready-builder-for-rhel-8-x86_64-rpms python38-devel --setopt install_weak_deps=falseCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
--setopt install_weak_deps=falseoption disables the installation of weak dependencies. Weak dependencies include recommended or suggested packages that are not strictly required but are often installed by default.
Verification
List all enabled repositories inside the container:
microdnf repolist
# microdnf repolistCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Ensure that the required repositories are listed.
List all installed packages:
rpm -qa
# rpm -qaCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Ensure that the required packages are listed.
Installing Red Hat packages that are not inside the Red Hat UBI repositories can limit the ability to distribute the container outside of subscribed RHEL systems.
7.6. Adding software to a UBI container on a unsubscribed host Link kopierenLink in die Zwischenablage kopiert!
You do not have to disable any repositories when adding software packages on unsubscribed RHEL systems.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Add a package to a running container based on the UBI standard or UBI init images. Do not disable any repositories. Use the
podman runcommand to run the container. then use thednf installcommand inside a container.For example, to add the
bzip2package to the UBI standard based container:podman run -it --name myubi registry.access.redhat.com/ubi10/ubi dnf install bzip2
$ podman run -it --name myubi registry.access.redhat.com/ubi10/ubi # dnf install bzip2Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example, to add the
bzip2package to the UBI init based container:podman run -it --name myubimin registry.access.redhat.com/ubi10/ubi-minimal microdnf install bzip2
$ podman run -it --name myubimin registry.access.redhat.com/ubi10/ubi-minimal # microdnf install bzip2Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
List all enabled repositories:
To list all enabled repositories inside the containers based on UBI standard or UBI init images:
dnf repolist
# dnf repolistCopy to Clipboard Copied! Toggle word wrap Toggle overflow To list all enabled repositories inside the containers based on UBI minimal containers:
microdnf repolist
# microdnf repolistCopy to Clipboard Copied! Toggle word wrap Toggle overflow
- Ensure that the required repositories are listed.
List all installed packages:
rpm -qa
# rpm -qaCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Ensure that the required packages are listed.
7.7. Building UBI-based images Link kopierenLink in die Zwischenablage kopiert!
You can create a UBI-based web server container from a Containerfile by using the Buildah utility. You have to disable all non-UBI dnf repositories to ensure that your image contains only Red Hat software that you can redistribute.
For UBI minimal images, use microdnf instead of dnf: RUN microdnf update -y && rm -rf /var/cache/yum and RUN microdnf install httpd -y && microdnf clean all commands.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create a
Containerfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build the container image:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Run the web server:
podman run -d --name=myweb -p 80:80 johndoe/webserver
# podman run -d --name=myweb -p 80:80 johndoe/webserver bbe98c71d18720d966e4567949888dc4fb86eec7d304e785d5177168a5965f64Copy to Clipboard Copied! Toggle word wrap Toggle overflow Test the web server:
curl http://localhost/index.html
# curl http://localhost/index.html The Web Server is RunningCopy to Clipboard Copied! Toggle word wrap Toggle overflow
7.8. Using Application Stream runtime images Link kopierenLink in die Zwischenablage kopiert!
Runtime images based on Application Streams offer a set of container images that you can use as the basis for your container builds.
Supported runtime images are Python, Ruby, s2-core, s2i-base, .NET Core, PHP. The runtime images are available in the Red Hat Container Catalog.
Because these UBI images contain the same basic software as their legacy image counterparts, you can learn about those images from the Using Red Hat Software Collections Container Images guide.
7.9. Getting UBI container image source code Link kopierenLink in die Zwischenablage kopiert!
Source code is available for all Red Hat UBI-based images in the form of downloadable container images. Source container images cannot be run, despite being packaged as containers. To install Red Hat source container images on your system, use the skopeo command, not the podman pull command.
Source container images are named based on the binary containers they represent. For example, for a particular standard RHEL UBI 10 container registry.access.redhat.com/ubi10:8.1-397 append -source to get the source container image (registry.access.redhat.com/ubi10:8.1-397-source).
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Use the
skopeo copycommand to copy the source container image to a local directory:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
skopeo inspectcommand to inspect the source container image:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Unpack all the content:
cd $HOME/TEST for f in $(ls); do tar xvf $f; done
$ cd $HOME/TEST $ for f in $(ls); do tar xvf $f; doneCopy to Clipboard Copied! Toggle word wrap Toggle overflow Check the results:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the results are correct, the image is ready to be used.
It could take several hours after a container image is released for its associated source container to become available.