Building, running, and managing containers
Using Podman, Buildah, and Skopeo on Red Hat Enterprise Linux
Abstract
Providing feedback on Red Hat documentation Copy linkLink copied to clipboard!
We appreciate your feedback on our documentation. Let us know how we can improve it.
Submitting feedback through Jira (account required)
- Log in to the Jira website.
- Click Create in the top navigation bar
- Enter a descriptive title in the Summary field.
- Enter your suggestion for improvement in the Description field. Include links to the relevant parts of the documentation.
- Click Create at the bottom of the dialogue.
Chapter 1. Introduction to containers Copy linkLink copied to clipboard!
Linux containers have emerged as a key open source application packaging and delivery technology, combining lightweight application isolation with the flexibility of image-based deployment methods. Red Hat Enterprise Linux implements Linux containers using core technologies such as:
- Control groups (cgroups) for resource management
- Namespaces for process isolation
- SELinux for security
- Secure multi-tenancy
These technologies reduce the potential for security exploits and provide you with an environment for producing and running enterprise-quality containers.
Red Hat OpenShift provides powerful command-line and Web UI tools for building, managing, and running containers in units referred to as pods. Red Hat allows you to build and manage individual containers and container images outside of OpenShift. This guide describes the tools provided to perform those tasks that run directly on Red Hat Enterprise Linux systems.
Unlike other container tools implementations, the tools described here do not center around the monolithic Docker container engine and docker command. Instead, Red Hat provides a set of command-line tools that can operate without a container engine. These include:
-
podman - for directly managing pods and container images (
run,stop,start,ps,attach,exec, and so on) - buildah - for building, pushing, and signing container images
- skopeo - for copying, inspecting, deleting, and signing images
- runc - for providing container run and build features to podman and buildah
- crun - an optional runtime that can be configured and gives greater flexibility, control, and security for rootless containers
Besides these tools, you can also use Podman Desktop, that is, a GUI-based application for container management. Podman Desktop is built on top of Podman, making it easy to create, manage, and run containerized applications visually.
Because these tools are compatible with the Open Container Initiative (OCI), they can be used to manage the same Linux containers that are produced and managed by Docker and other OCI-compatible container engines. However, they are especially suited to run directly on Red Hat Enterprise Linux, in single-node use cases.
For a multi-node container platform, see OpenShift and Using the CRI-O Container Engine for details.
1.1. Characteristics of Podman, Podman Desktop, Buildah, and Skopeo Copy linkLink copied to clipboard!
The Podman, Podman Desktop, Skopeo, and Buildah tools were developed to replace Docker command features. Each tool in this scenario is more lightweight and focused on a subset of features.
The main advantages of Podman, Podman Desktop, Skopeo and Buildah tools include:
- Running in rootless mode - rootless containers are much more secure, as they run without any added privileges
- No daemon required - these tools have much lower resource requirements at idle, because if you are not running containers, Podman is not running. Docker, conversely, have a daemon always running
-
Native
systemdintegration - Podman allows you to createsystemdunit files and run containers as system services
The characteristics of Podman, Podman Desktop, Skopeo, and Buildah include:
-
Podman, Buildah, and the CRI-O container engine all use the same back-end store directory,
/var/lib/containers, instead of using the Docker storage location/var/lib/docker, by default. - Although Podman, Buildah, and CRI-O share the same storage directory, they cannot interact with each other’s containers. Those tools can share images.
- To interact programmatically with Podman, you can use the Podman v2.0 RESTful API, it works in both a rootful and a rootless environment. For more information, see Using the container-tools API chapter.
- Podman Desktop provides a simple and intuitive interface to run your application workload on a Podman engine.
1.2. Running containers without Docker Copy linkLink copied to clipboard!
Red Hat removed the Docker container engine and the docker command from RHEL 10.
If you still want to use Docker in RHEL, you can get Docker from different upstream projects, but it is unsupported in RHEL 10.
-
You can install the
podman-dockerpackage, every time you run adockercommand, it actually runs apodmancommand. -
Podman also supports the Docker Socket API, so the
podman-dockerpackage also sets up a link between/var/run/docker.sockand/var/run/podman/podman.sock. As a result, you can continue to run your Docker API commands withdocker-pyanddocker-composetools without requiring the Docker daemon. Podman will service the requests. -
The
podmancommand, like thedockercommand, can build container images from aContainerfileorDockerfile. The available commands that are usable inside aContainerfileand aDockerfileare equivalent. -
Options to the
dockercommand that are not supported bypodmaninclude network, node, plugin (podmandoes not support plugins), rename (use rm and create to rename containers withpodman), secret, service, stack, and swarm (podmandoes not support Docker Swarm). The container and image options are used to run subcommands that are used directly inpodman.
1.3. Supported architectures for container deployment in RHEL Copy linkLink copied to clipboard!
Red Hat provides container images and container-related software for the following computer architectures:
- AMD64 and Intel 64 (base and layered images; no support for 32-bit architectures)
- PowerPC 8 and 9 64-bit (base image and most layered images)
- 64-bit IBM Z (base image and most layered images)
- ARM 64-bit (base image only)
Although not all Red Hat images were supported across all architectures at first, nearly all are now available on all listed architectures.
1.4. Installing container tools Copy linkLink copied to clipboard!
This procedure shows how you can install the container-tools meta-package which contains the Podman, Buildah, Skopeo, CRIU, Udica, and all required libraries.
The stable streams are not available on RHEL 9. To receive stable access to Podman, Buildah, Skopeo, and others, use the RHEL EUS subscription.
Procedure
- Install RHEL.
Register RHEL: Enter your user name and password. The user name and password are the same as your login credentials for Red Hat Customer Portal:
subscription-manager register
# subscription-manager register Registering to: subscription.rhsm.redhat.com:443/subscription Username: <username> Password: <password>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Subscribe to RHEL.
To auto-subscribe to RHEL:
subscription-manager attach --auto
# subscription-manager attach --autoCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Install the
container-toolsmeta-package:dnf install container-tools
# dnf install container-toolsCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can also install
podman,buildah, andskopeoindividually if you prefer.Optional: Install the
podman-dockerpackage:dnf install podman-docker
# dnf install podman-dockerCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
podman-dockerpackage replaces the Docker command-line interface anddocker-apiwith the matching Podman commands instead.
1.5. Installing Podman Desktop Copy linkLink copied to clipboard!
Podman Desktop helps developers to perform their daily development tasks and visualize their development environment, such as the number of pods or containers running. You can run this tool on three different operating systems; macOS, Windows, and Linux. Podman Desktop runs your workloads on a Podman engine and therefore, provides you Podman-native capabilities to interact with your containerized applications. As a developer, you can:
- Create and manage containers or pods
- Manage container images
- Deploy containers or pods to Kubernetes using Kind, Lima, Minikube or OpenShift
- Manage Docker compatibility to run your Docker workloads on a Podman engine
- Integrate your tools using extensions
For installation, use the subscription manager package on a RHEL 10 machine.
Prerequisites
- You have a RHEL 10 machine.
-
You have registered with the
subscription-managerusing either your account details or the activation key.
Procedure
Open a terminal, and enable the RHEL extensions repository:
subscription-manager repos --enable rhel-10-for-$(arch)-extensions-rpms
# subscription-manager repos --enable rhel-10-for-$(arch)-extensions-rpmsCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Enter your password when prompted.
Install Podman Desktop:
dnf install podman-desktop
# dnf install podman-desktopCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Enter
yto confirm the installed size. -
Enter
yto import the GPG key and complete the installation.
Verification
- Enter Podman Desktop in the search box at the top of your home screen, and click the Podman Desktop application to open it.
- Follow the prompts to complete a quick onboarding process with the application.
Podman is included with a RHEL subscription, and the application automatically detects and runs it.
Next steps
Perform basic tasks, such as:
1.6. Special considerations for rootless containers Copy linkLink copied to clipboard!
There are several considerations when running containers as a non-root user:
-
The path to the host container storage is different for root users (
/var/lib/containers/storage) and non-root users ($HOME/.local/share/containers/storage). - Users running rootless containers are given special permission to run as a range of user and group IDs on the host system. However, they have no root privileges to the operating system on the host.
-
If you change the
/etc/subuidor/etc/subgidmanually, you have to run thepodman system migratecommand to allow the new changes to be applied. -
If you need to configure your rootless container environment, create configuration files in your home directory (
$HOME/.config/containers). Configuration files includestorage.conf(for configuring storage) andcontainers.conf(for a variety of container settings). You could also create aregistries.conffile to identify container registries that are available when you use Podman to pull, search, or run images. There are some system features you cannot change without root privileges. For example, you cannot change the system clock by setting a
SYS_TIMEcapability inside a container and running the network time service (ntpd). You have to run that container as root, bypassing your rootless container environment and using the root user’s environment. For example:podman run -d --cap-add SYS_TIME ntpd
# podman run -d --cap-add SYS_TIME ntpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that this example allows
ntpdto adjust time for the entire system, and not just within the container.A rootless container cannot access a port numbered less than 1024. Inside the rootless container namespace it can, for example, start a service that exposes port 80 from an httpd service from the container, but it is not accessible outside of the namespace:
podman run -d httpd
$ podman run -d httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow However, a container would need root privileges, using the root user’s container environment, to expose that port to the host system:
podman run -d -p 80:80 httpd
# podman run -d -p 80:80 httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow The administrator of a workstation can allow users to expose services on ports numbered lower than 1024, but they should understand the security implications. A regular user could, for example, run a web server on the official port 80 and make external users believe that it was configured by the administrator. This is acceptable on a workstation for testing, but might not be a good idea on a network-accessible development server, and definitely should not be done on production servers. To allow users to bind to ports down to port 80 run the following command:
echo 80 > /proc/sys/net/ipv4/ip_unprivileged_port_start
# echo 80 > /proc/sys/net/ipv4/ip_unprivileged_port_startCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.7. Using modules for advanced Podman configuration Copy linkLink copied to clipboard!
You can use Podman modules to load a predetermined set of configurations. Podman modules are containers.conf files in the Tom’s Obvious Minimal Language (TOML) format.
These modules are located in the following directories, or their subdirectories:
-
For rootless users:
$HOME/.config/containers/containers.conf.modules -
For root users:
/etc/containers/containers.conf.modules, or/usr/share/containers/containers.conf.modules
You can load the modules on-demand with the podman --module <your_module_name> command to override the system and user configuration files. Working with modules involve the following facts:
-
You can specify modules multiple times by using the
--moduleoption. -
If
<your_module_name>is the absolute path, the configuration file will be loaded directly. - The relative paths are resolved relative to the three module directories mentioned previously.
-
Modules in
$HOMEoverride those in the/etc/and/usr/share/directories.
For more information, see the containers.conf(5) man page on your system.
Chapter 2. Types of container images Copy linkLink copied to clipboard!
The container image is a binary that includes all of the requirements for running a single container, and metadata describing its needs and capabilities.
There are two types of container images:
- Red Hat Enterprise Linux Base Images (RHEL base images)
- Red Hat Universal Base Images (UBI images)
Both types of container images are built from portions of Red Hat Enterprise Linux. By using these containers, users can benefit from great reliability, security, performance and life cycles.
The main difference between the two types of container images is that the UBI images allow you to share container images with others. You can build a containerized application using UBI, push it to your choice of registry server, easily share it with others, and even deploy it on non-Red Hat platforms. The UBI images are designed to be a foundation for cloud-native and web applications use cases developed in containers.
2.1. General characteristics of RHEL container images Copy linkLink copied to clipboard!
Following characteristics apply to both RHEL base images and UBI images.
In general, RHEL container images are:
- Supported: Supported by Red Hat for use with containerized applications. They contain the same secured, tested, and certified software packages found in Red Hat Enterprise Linux.
- Cataloged: Listed in the Red Hat Container Catalog, with descriptions, technical details, and a health index for each image.
- Updated: Offered with a well-defined update schedule, to get the latest software, see Red Hat Container Image Updates article.
- Tracked: Tracked by Red Hat Product Errata to help understand the changes that are added into each update.
- Reusable: The container images need to be downloaded and cached in your production environment once. Each container image can be reused by all containers that include it as their foundation.
2.2. Characteristics of UBI images Copy linkLink copied to clipboard!
The UBI images allow you to share container images with others. Four UBI images are offered: micro, minimal, standard, and init. Pre-build language runtime images and DNF repositories are available to build your applications.
Following characteristics apply to UBI images:
- Built from a subset of RHEL content: Red Hat Universal Base images are built from a subset of normal Red Hat Enterprise Linux content.
- Redistributable: UBI images allow standardization for Red Hat customers, partners, ISVs, and others. With UBI images, you can build your container images on a foundation of official Red Hat software that can be freely shared and deployed.
- Provide a set of four base images: micro, minimal, standard, and init.
- Provide a set of pre-built language runtime container images: The runtime images based on Application Streams provide a foundation for applications that can benefit from standard, supported runtimes such as python, perl, php, dotnet, nodejs, and ruby.
Provide a set of associated DNF repositories: DNF repositories include RPM packages and updates that allow you to add application dependencies and rebuild UBI container images.
-
The
ubi-10-baseosrepository holds the redistributable subset of RHEL packages you can include in your container. -
The
ubi-10-appstreamrepository holds Application streams packages that you can add to a UBI image to help you standardize the environments you use with applications that require particular runtimes. -
Adding UBI RPMs: You can add RPM packages to UBI images from preconfigured UBI repositories. If you happen to be in a disconnected environment, you must allowlist the UBI Content Delivery Network (
https://cdn-ubi.redhat.com) to use that feature. See the Connect to https://cdn-ubi.redhat.com solution for details.
-
The
- Licensing: You are free to use and redistribute UBI images, provided you adhere to the Red Hat Universal Base Image End User Licensing Agreement.
All of the layered images are based on UBI images. To check on which UBI image is your image based, display the Containerfile in the Red Hat Container Catalog and ensure that the UBI image contains all required content.
2.3. Understanding the UBI standard images Copy linkLink copied to clipboard!
The standard images (named ubi) are designed for any application that runs on RHEL. The key features of UBI standard images include:
-
init system: All the features of the
systemdinitialization system you need to managesystemdservices are available in the standard base images. These init systems let you install RPM packages that are pre-configured to start up services automatically, such as a Web server (httpd) or FTP server (vsftpd). -
dnf: You have access to free DNF repositories for adding and updating software. You can use the standard set of
dnfcommands (dnf,dnf-config-manager,dnfdownloader, and so on). -
utilities: Utilities include
tar,dmidecode,gzip,getfacland further ACL commands,dmsetupand further device mapper commands, between other utilities not mentioned here.
2.4. Understanding the UBI init images Copy linkLink copied to clipboard!
The UBI init images, named ubi-init, contain the systemd initialization system, making them useful for building images in which you want to run systemd services, such as a web server or file server. The init image contains more content than minimal images but less than standard images.
Because the ubi10-init image builds on top of the ubi10 image, their contents are mostly the same. However, there are a few critical differences:
ubi10-init:-
CMD is set to
/sbin/initto start thesystemdInit service by default -
includes
psand process related commands (procps-ngpackage) -
sets
SIGRTMIN+3as theStopSignal, assystemdinubi10-initignores normal signals to exit (SIGTERMandSIGKILL), but will terminate if it receivesSIGRTMIN+3
-
CMD is set to
ubi10:-
CMD is set to
/bin/bash -
does not include
psand process related commands (procps-ngpackage) -
does not ignore normal signals to exit (
SIGTERMandSIGKILL)
-
CMD is set to
2.5. Understanding the UBI minimal images Copy linkLink copied to clipboard!
The UBI minimal images, named ubi-minimal offer a minimized pre-installed content set and a package manager (microdnf). As a result, you can use a Containerfile while minimizing the dependencies included in the image.
The key features of UBI minimal images include:
- Small size: Minimal images are about 92M on disk and 32M, when compressed. This makes it less than half the size of the standard images.
-
Software installation (
microdnf): Instead of including the fully-developeddnffacility for working with software repositories and RPM software packages, the minimal images includes themicrodnfutility. Themicrodnfis a scaled-down version ofdnfallowing you to enable and disable repositories, remove and update packages, and clean out cache after packages have been installed. -
Based on RHEL packaging: Minimal images incorporate regular RHEL software RPM packages, with a few features removed. Minimal images do not include initialization and service management system, such as
systemdor System V init, Python run-time environment, and some shell utilities. You can rely on RHEL repositories for building your images, while carrying the smallest possible amount of overhead. Modules for
microdnfare supported: Modules used withmicrodnfcommand let you install multiple versions of the same software, when available. You can usemicrodnf module enable,microdnf module disable, andmicrodnf module resetto enable, disable, and reset a module stream, respectively.For example, to enable the
nodejs:14module stream inside the UBI minimal container, enter:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Red Hat only supports the latest version of UBI and does not support parking on a dot release. If you need to park on a specific dot release, please take a look at Extended Update Support.
2.6. Understanding the UBI micro images Copy linkLink copied to clipboard!
The ubi-micro is the smallest possible UBI image, obtained by excluding a package manager and all of its dependencies which are normally included in a container image. This minimizes the attack surface of container images based on the ubi-micro image and is suitable for minimal applications, even if you use UBI Standard, Minimal, or Init for other applications. The container image without the Linux distribution packaging is called a Distroless container image.
Chapter 3. Working with container registries Copy linkLink copied to clipboard!
A container image registry is a repository or collection of repositories for storing container images and container-based application artifacts. The /etc/containers/registries.conf file is a system-wide configuration file containing the container image registries that can be used by the various container tools such as Podman, Buildah, and Skopeo.
If the container image given to a container tool is not fully qualified, then the container tool references the registries.conf file. Within the registries.conf file, you can specify aliases for short names, granting administrators full control over where images are pulled from when not fully qualified. For example, the podman pull example.com/example_image command pulls a container image from the example.com registry to your local system as specified in the registries.conf file.
3.1. Container registries Copy linkLink copied to clipboard!
A container registry is a repository or collection of repositories for storing container images and container-based application artifacts. The registries that Red Hat provides are:
- registry.redhat.io (requires authentication)
- registry.access.redhat.com (requires no authentication)
- registry.connect.redhat.com (holds Red Hat Partner Connect program images)
To get container images from a remote registry, such as Red Hat’s own container registry, and add them to your local system, use the podman pull command:
podman pull <registry>[:<port>]/[<namespace>/]<name>:<tag>
# podman pull <registry>[:<port>]/[<namespace>/]<name>:<tag>
where <registry>[:<port>]/[<namespace>/]<name>:<tag> is the name of the container image.
For example, the registry.redhat.io/ubi10/ubi container image is identified by:
-
Registry server (
registry.redhat.io) -
Namespace (
ubi10) -
Image name (
ubi)
If there are multiple versions of the same image, add a tag to explicitly specify the image name. By default, Podman uses the :latest tag, for example ubi10/ubi:latest.
Some registries also use <namespace> to distinguish between images with the same <name> owned by different users or organizations. For example:
| Namespace | Examples (<namespace>/<name>) |
|---|---|
| organization |
|
| login (user name) |
|
| role |
|
Use fully qualified image names including registry, namespace, image name, and tag. When using short names, there is always an inherent risk of spoofing. Add registries that are trusted, that is, registries that do not allow unknown or anonymous users to create accounts with arbitrary names. For example, a user wants to pull the example container image from example.registry.com registry. If example.registry.com is not first in the search list, an attacker could place a different example image at a registry earlier in the search list. The user would accidentally pull and run the attacker image rather than the intended content.
For details on the transition to registry.redhat.io, see Red Hat Container Registry Authentication. Before you can pull containers from registry.redhat.io, you need to authenticate using your RHEL Subscription credentials.
3.2. Configuring container registries Copy linkLink copied to clipboard!
You can display the container registries by using the podman info --format command:
The podman info command is available in Podman 4.0.0 or later.
You can edit the list of container registries in the registries.conf configuration file. As a root user, edit the /etc/containers/registries.conf file to change the default system-wide search settings.
As a user, create the $HOME/.config/containers/registries.conf file to override the system-wide settings.
unqualified-search-registries = ["registry.access.redhat.com", "registry.redhat.io", "docker.io"] short-name-mode = "enforcing"
unqualified-search-registries = ["registry.access.redhat.com", "registry.redhat.io", "docker.io"]
short-name-mode = "enforcing"
By default, the podman pull and podman search commands search for container images from registries listed in the unqualified-search-registries list in the given order.
- Configuring a local container registry
You can configure a local container registry without the TLS verification. You have two options on how to disable TLS verification. First, you can use the
--tls-verify=falseoption in Podman. Second, you can setinsecure=truein theregistries.conffile:[[registry]] location="localhost:5000" insecure=true
[[registry]] location="localhost:5000" insecure=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Blocking a registry, namespace, or image
You can define registries the local system is not allowed to access. You can block a specific registry by setting
blocked=true.[[registry]] location = "registry.example.org" blocked = true
[[registry]] location = "registry.example.org" blocked = trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can also block a namespace by setting the prefix to
prefix="registry.example.org/namespace". For example, pulling the image by using thepodman pull registry. example.org/example/image:latestcommand will be blocked, because the specified prefix is matched.[[registry]] location = "registry.example.org" prefix="registry.example.org/namespace" blocked = true
[[registry]] location = "registry.example.org" prefix="registry.example.org/namespace" blocked = trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe
prefixis optional, default value is the same as thelocationvalue.You can block a specific image by setting
prefix="registry.example.org/namespace/image".[[registry]] location = "registry.example.org" prefix="registry.example.org/namespace/image" blocked = true
[[registry]] location = "registry.example.org" prefix="registry.example.org/namespace/image" blocked = trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Mirroring registries
You can set a registry mirror in cases you cannot access the original registry. For example, you cannot connect to the internet, because you work in a highly-sensitive environment. You can specify multiple mirrors that are contacted in the specified order. For example, when you run
podman pull registry.example.com/myimage:latestcommand, themirror-1.comis tried first, thenmirror-2.com.Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-pull(1)andpodman-info(1)man pages on your system.
3.3. Searching for container images Copy linkLink copied to clipboard!
Using the podman search command you can search selected container registries for images. You can also search for images in the Red Hat Container Catalog. The Red Hat Container Registry includes the image description, contents, health index, and other information.
The podman search command is not a reliable way to determine the presence or existence of an image. The podman search behavior of the v1 and v2 Docker distribution API is specific to the implementation of each registry. Some registries may not support searching at all. Searching without a search term only works for registries that implement the v2 API. The same holds for the docker search command.
To search for the postgresql-10 images in the quay.io registry, follow the steps.
Prerequisites
-
The
container-toolsmeta-package is installed. - The registry is configured.
Procedure
Authenticate to the registry:
podman login quay.io
# podman login quay.ioCopy to Clipboard Copied! Toggle word wrap Toggle overflow Search for the image:
To search for a particular image on a specific registry, enter:
podman search quay.io/postgresql-10
# podman search quay.io/postgresql-10 INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED redhat.io registry.redhat.io/rhel10/postgresql-10 This container image ... 0 redhat.io registry.redhat.io/rhscl/postgresql-10-rhel7 PostgreSQL is an ... 0Copy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, to display all images provided by a particular registry, enter:
podman search quay.io/
# podman search quay.io/Copy to Clipboard Copied! Toggle word wrap Toggle overflow To search for the image name in all registries, enter:
podman search postgresql-10
# podman search postgresql-10Copy to Clipboard Copied! Toggle word wrap Toggle overflow To display the full descriptions, pass the
--no-truncoption to the command.For more information, see the
podman-search(1)man page on your system.
3.4. Configuring short-name aliases Copy linkLink copied to clipboard!
Always to pull an image by its fully-qualified name. However, it is customary to pull images by short names. For example, you can use ubi10 instead of registry.access.redhat.com/ubi10:latest.
The registries.conf file allows to specify aliases for short names, giving administrators full control over where images are pulled from. Aliases are specified in the table in the form "name" = "value". You can see the lists of aliases in the /etc/containers/registries.conf.d directory. Red Hat ships a set of aliases in this directory. For example, podman pull ubi10 directly resolves to the right image, that is registry.access.redhat.com/ubi10:latest.
For example:
unqualified-search-registries=["registry.fedoraproject.org", "quay.io"] [aliases] "fedora"="registry.fedoraproject.org/fedora"
unqualified-search-registries=["registry.fedoraproject.org", "quay.io"]
[aliases]
"fedora"="registry.fedoraproject.org/fedora"
The short-names modes are:
-
enforcing: If no matching alias is found during the image pull, Podman prompts the user to choose one of the unqualified-search registries. If the selected image is pulled successfully, Podman automatically records a new short-name alias in the
$HOME/.cache/containers/short-name-aliases.conffile (rootless user) or in the/var/cache/containers/short-name-aliases.conf(root user). If the user cannot be prompted (for example, stdin or stdout are not a TTY), Podman fails. Note that theshort-name-aliases.conffile has precedence over theregistries.conffile if both specify the same alias. - permissive: Similar to enforcing mode, but Podman does not fail if the user cannot be prompted. Instead, Podman searches in all unqualified-search registries in the given order. Note that no alias is recorded.
- disabled: All unqualified-search registries are tried in a given order, no alias is recorded.
Chapter 4. Working with container images Copy linkLink copied to clipboard!
The Podman tool is designed to work with container images. You can use this tool to pull the image, inspect, tag, save, load, redistribute, and define the image signature.
4.1. Pulling images from registries Copy linkLink copied to clipboard!
Use the podman pull command to get the image to your local system.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Log in to the registry.redhat.io registry:
podman login registry.redhat.io
$ podman login registry.redhat.io Username: <username> Password: <password> Login Succeeded!Copy to Clipboard Copied! Toggle word wrap Toggle overflow Pull the registry.redhat.io/ubi10/ubi container image:
podman pull registry.redhat.io/ubi10/ubi
$ podman pull registry.redhat.io/ubi10/ubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
List all images pulled to your local system:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.redhat.io/ubi10/ubi latest 3269c37eae33 7 weeks ago 208 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-pull(1)man page on your system.
4.2. Pulling container images using short-name aliases Copy linkLink copied to clipboard!
You can use secure short names to get the image to your local system. The following procedure describes how to pull a fedora or nginx container image.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Pull the container image:
Pull the
fedoraimage:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Alias is found and the
registry.fedoraproject.org/fedoraimage is securely pulled. Theunqualified-search-registrieslist is not used to resolvefedoraimage name.Pull the
nginximage:Copy to Clipboard Copied! Toggle word wrap Toggle overflow If no matching alias is found, you are prompted to choose one of the
unqualified-search-registrieslist. If the selected image is pulled successfully, a new short-name alias is recorded locally, otherwise an error occurs.
Verification
List all images pulled to your local system:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.fedoraproject.org/fedora latest 28317703decd 12 days ago 184 MB docker.io/library/nginx latest 08b152afcfae 13 days ago 137 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow
4.3. Listing images Copy linkLink copied to clipboard!
Use the podman images command to list images in your local storage.
Prerequisites
-
The
container-toolsmeta-package is installed. - A pulled image is available on the local system.
Procedure
List all images in the local storage:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.access.redhat.com/ubi10/ubi latest 3269c37eae33 6 weeks ago 208 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow
For more information, see the podman-images(1) man page on your system.
4.4. Inspecting local images Copy linkLink copied to clipboard!
After you pull an image to your local system and run it, you can use the podman inspect command to investigate the image. For example, use it to understand what the image does and check what software is inside the image. The podman inspect command displays information about containers and images identified by name or ID.
Prerequisites
-
The
container-toolsmeta-package is installed. - A pulled image is available on the local system.
Procedure
Inspect the
registry.redhat.io/ubi10/ubiimage:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
"Cmd"key specifies a default command to run within a container. You can override this command by specifying a command as an argument to thepodman runcommand. This ubi10/ubi container will execute the bash shell if no other argument is given when you start it withpodman run. If an"Entrypoint"key was set, its value would be used instead of the"Cmd"value, and the value of"Cmd"is used as an argument to the Entrypoint command.
4.5. Inspecting remote images Copy linkLink copied to clipboard!
Use the skopeo inspect command to display information about an image from a remote container registry before you pull the image to your system.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Inspect the
registry.redhat.io/ubi10/ubi-initimage:Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
skopeo-inspect(1)man page on your system.
4.6. Copying container images Copy linkLink copied to clipboard!
You can use the skopeo copy command to copy a container image from one registry to another. For example, you can populate an internal repository with images from external registries, or sync image registries in two different locations.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Copy the
skopeocontainer image fromdocker://quay.iotodocker://registry.example.com:skopeo copy docker://quay.io/skopeo/stable:latest docker://registry.example.com/skopeo:latest
$ skopeo copy docker://quay.io/skopeo/stable:latest docker://registry.example.com/skopeo:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow Refer to
skopeo-copy(1)man page on your system for more information.
4.7. Copying image layers to a local directory Copy linkLink copied to clipboard!
You can use the skopeo copy command to copy the layers of a container image to a local directory.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create the
/var/lib/images/nginxdirectory:mkdir -p /var/lib/images/nginx
$ mkdir -p /var/lib/images/nginxCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the layers of the
docker://docker.io/nginx:latest imageto the newly created directory:skopeo copy docker://docker.io/nginx:latest dir:/var/lib/images/nginx
$ skopeo copy docker://docker.io/nginx:latest dir:/var/lib/images/nginxCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Display the content of the
/var/lib/images/nginxdirectory:ls /var/lib/images/nginx
$ ls /var/lib/images/nginx 08b11a3d692c1a2e15ae840f2c15c18308dcb079aa5320e15d46b62015c0f6f3 ... 4fcb23e29ba19bf305d0d4b35412625fea51e82292ec7312f9be724cb6e31ffd manifest.json versionCopy to Clipboard Copied! Toggle word wrap Toggle overflow Refer to
skopeo-copy(1)man page on your system for more information.
4.8. Tagging images Copy linkLink copied to clipboard!
Use the podman tag command to add an additional name to a local image. This additional name can consist of several parts: <registryhost>/<username>/<name>:<tag>.
Prerequisites
-
The
container-toolsmeta-package is installed. - A pulled image is available on the local system.
Procedure
List all images:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.redhat.io/ubi10/ubi latest 3269c37eae33 7 weeks ago 208 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow Assign the
myubiname to theregistry.redhat.io/ubi10/ubiimage using one of the following options:The image name:
podman tag registry.redhat.io/ubi10/ubi myubi
$ podman tag registry.redhat.io/ubi10/ubi myubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow The image ID:
podman tag 3269c37eae33 myubi
$ podman tag 3269c37eae33 myubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow Both commands give you the same result.
List all images:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.redhat.io/ubi10/ubi latest 3269c37eae33 2 months ago 208 MB localhost/myubi latest 3269c37eae33 2 months ago 208 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow Notice that the default tag is
latestfor both images. You can see all the image names are assigned to the single image ID 3269c37eae33.Add the
10tag to theregistry.redhat.io/ubi10/ubiimage using either:The image name:
podman tag registry.redhat.io/ubi10/ubi myubi:10
$ podman tag registry.redhat.io/ubi10/ubi myubi:10Copy to Clipboard Copied! Toggle word wrap Toggle overflow The image ID:
podman tag 3269c37eae33 myubi:10
$ podman tag 3269c37eae33 myubi:10Copy to Clipboard Copied! Toggle word wrap Toggle overflow Both commands give you the same result.
Verification
List all images:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.redhat.io/ubi10/ubi latest 3269c37eae33 2 months ago 208 MB localhost/myubi latest 3269c37eae33 2 months ago 208 MB localhost/myubi 10 3269c37eae33 2 months ago 208 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow Notice that the default tag is
latestfor both images. You can see all the image names are assigned to the single image ID 3269c37eae33.
After tagging the registry.redhat.io/ubi10/ubi image, you have three options to run the container:
-
by ID (
3269c37eae33) -
by name (
localhost/myubi:latest) by name (
localhost/myubi:10)For more information, see
podman-tag(1)man page on your system.
4.9. Building multi-architecture images Copy linkLink copied to clipboard!
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
-
Create
Containerfilesfor each architecture you want to support. Build images for each architecture. For example:
podman build --platform linux/arm64,linux/amd64 --manifest <registry>/<image> .
$ podman build --platform linux/arm64,linux/amd64 --manifest <registry>/<image> .Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
--platform linux/arm64,linux/amd64option specifies the target platforms for which the container image is being built. -
The
--manifest <registry>/<image>option creates a manifest list with the specified name, that is<registry>/<image>, and adds the newly-built images to them. A manifest list is a collection of image manifests, each one targeting a different architecture.
-
The
Push the manifest list to the registry:
podman manifest push <registry>/<image>
$ podman manifest push <registry>/<image>Copy to Clipboard Copied! Toggle word wrap Toggle overflow This manifest list acts as a single entry point for pulling the multi-architecture container.
As a result, you can pull the appropriate container image for your platform, based on a single manifest list.
You can also remove items from the manifest list by using the
podman manifest remove <manifest_list> <digest_ID>command, where<digest_ID>is the SHA-256 checksum of the container image. For example:podman manifest remove <registry>/<image> sha256:cb8a924afdf….
Verification
Display the manifest list:
podman manifest inspect <registry>/<image>
$ podman manifest inspect <registry>/<image>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Refer to the
podman-build(1)andpodman-manifest(1)man page on your system for more information.
4.10. Saving and loading images Copy linkLink copied to clipboard!
Use the podman save command to save an image to a container archive. You can restore it later to another container environment or send it to someone else. You can use --format option to specify the archive format. The supported formats are:
-
docker-archive -
oci-archive -
oci-dir(directory with oci manifest type) -
docker-archive(directory with v2s2 manifest type)
The default format is the docker-archive format.
Use the podman load command to load an image from the container image archive into the container storage.
Prerequisites
-
The
container-toolsmeta-package is installed. - A pulled image is available on the local system.
Procedure
Save the
registry.redhat.io/rhel10/support-toolsimage as a tarball:In the default
docker-archiveformat:podman save -o mysupport-tools.tar registry.redhat.io/rhel10/support-tools:latest
$ podman save -o mysupport-tools.tar registry.redhat.io/rhel10/support-tools:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow In the
oci-archiveformat, using the--formatoption:podman save -o mysupport-tools-oci.tar --format=oci-archive registry.redhat.io/rhel10/support-tools
$ podman save -o mysupport-tools-oci.tar --format=oci-archive registry.redhat.io/rhel10/support-toolsCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
mysupport-tools.tarandmysupport-tools-oci.tararchives are stored in your current directory. The next steps are performed with themysupport-tools.tartarball.
Check the file type of
mysupport-tools.tar:file mysupport-tools.tar
$ file mysupport-tools.tar mysupport-tools.tar: POSIX tar archiveCopy to Clipboard Copied! Toggle word wrap Toggle overflow To load the
registry.redhat.io/rhel10/support-tools:latestimage from themysupport-tools.tar:podman load -i mysupport-tools.tar
$ podman load -i mysupport-tools.tar ... Loaded image(s): registry.redhat.io/rhel10/support-tools:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-save(1)andpodman-load(1)man pages on your system.
4.11. Redistributing UBI images Copy linkLink copied to clipboard!
Use podman push command to push a UBI image to your own, or a third party, registry and share it with others. You can upgrade or add to that image from UBI dnf repositories as you like.
Prerequisites
-
The
container-toolsmeta-package is installed. - A pulled image is available on the local system.
Procedure
Optional: Add an additional name to the
ubiimage:podman tag registry.redhat.io/ubi10/ubi registry.example.com:5000/ubi10/ubi
# podman tag registry.redhat.io/ubi10/ubi registry.example.com:5000/ubi10/ubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow Push the
registry.example.com:5000/ubi10/ubiimage from your local storage to a registry:podman push registry.example.com:5000/ubi10/ubi
# podman push registry.example.com:5000/ubi10/ubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow
While there are few restrictions on how you use these images, there are some restrictions about how you can refer to them. For example, you cannot call those images Red Hat certified or Red Hat supported unless you certify it through the Red Hat Partner Connect Program, either with Red Hat Container Certification or Red Hat OpenShift Operator Certification.
4.12. Removing images Copy linkLink copied to clipboard!
Use the podman rmi command to remove locally stored container images. You can remove an image by its ID or name.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
List all images on your local system:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.redhat.io/rhel10/support-tools latest 4b32d14201de 7 weeks ago 228 MB registry.redhat.io/ubi10/ubi latest 3269c37eae33 7 weeks ago 208 MB localhost/myubi X.Y 3269c37eae33 7 weeks ago 208 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow List all containers:
podman ps -a
$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7ccd6001166e registry.redhat.io/rhel10/support-tools:latest usr/bin/bash 6 seconds ago Up 5 seconds ago my-support-toolsCopy to Clipboard Copied! Toggle word wrap Toggle overflow To remove the
registry.redhat.io/rhel10/support-toolsimage, you have to stop all containers running from this image by using thepodman stopcommand. You can stop a container by its ID or name.Stop the
my-support-toolscontainer:podman stop my-support-tools
$ podman stop my-support-tools 7ccd6001166e9720c47fbeb077e0afd0bb635e74a1b0ede3fd34d09eaf5a52e9Copy to Clipboard Copied! Toggle word wrap Toggle overflow Remove the
registry.redhat.io/rhel10/support-toolsimage:podman rmi registry.redhat.io/rhel10/support-tools
$ podman rmi registry.redhat.io/rhel10/support-toolsCopy to Clipboard Copied! Toggle word wrap Toggle overflow To remove multiple images:
podman rmi registry.redhat.io/rhel10/support-tools registry.redhat.io/ubi10/ubi
$ podman rmi registry.redhat.io/rhel10/support-tools registry.redhat.io/ubi10/ubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow To remove all images from your system:
podman rmi -a
$ podman rmi -aCopy to Clipboard Copied! Toggle word wrap Toggle overflow To remove images that have multiple names (tags) associated with them, add the
-foption to remove them:podman rmi -f 1de7d7b3f531
$ podman rmi -f 1de7d7b3f531 1de7d7b3f531...Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
-
List all images by using the
podman imagescommand to verify that container images were removed.
Chapter 5. Working with containers Copy linkLink copied to clipboard!
Containers represent a running or stopped process created from the files located in a decompressed container image. You can use the Podman tool to work with containers.
5.1. Podman run command Copy linkLink copied to clipboard!
The podman run command runs a process in a new container based on the container image. If the container image is not already loaded then podman run pulls the image, and all image dependencies, from the repository in the same way running podman pull image, before it starts the container from that image. The container process has its own file system, its own networking, and its own isolated process tree.
The podman run command has the form:
podman run [options] image [command [arg ...]]
podman run [options] image [command [arg ...]]
Basic options are:
-
--detach (-d): Runs the container in the background and prints the new container ID. -
--attach (-a): Runs the container in the foreground mode. -
--name (-n): Assigns a name to the container. If a name is not assigned to the container with--namethen it generates a random string name. This works for both background and foreground containers. -
--rm: Automatically remove the container when it exits. Note that the container will not be removed when it could not be created or started successfully. -
--tty (-t): Allocates and attaches the pseudo-terminal to the standard input of the container. -
--interactive (-i): For interactive processes, use-iand-ttogether to allocate a terminal for the container process. The-i -tis often written as-it.
5.2. Running commands in a container from the host Copy linkLink copied to clipboard!
Use the podman run command to display the type of operating system of the container.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Display the type of operating system of the container based on the
registry.access.redhat.com/ubi10/ubicontainer image using thecat /etc/os-releasecommand:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all containers.
podman ps
$ podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESCopy to Clipboard Copied! Toggle word wrap Toggle overflow Because of the
--rmoption you should not see any container. The container was removed.
5.3. Running commands inside the container Copy linkLink copied to clipboard!
Use the podman run command to run a container interactively.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Run the container named
myubibased on theregistry.redhat.io/ubi10/ubiimage:podman run --name=myubi -it registry.access.redhat.com/ubi10/ubi /bin/bash
$ podman run --name=myubi -it registry.access.redhat.com/ubi10/ubi /bin/bash [root@6ccffd0f6421 /]#Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
-ioption creates an interactive session. Without the-toption, the shell stays open, but you cannot type anything to the shell. -
The
-toption opens a terminal session. Without the-ioption, the shell opens and then exits.
-
The
Install the
procps-ngpackage containing a set of system utilities (for exampleps,top,uptime, and so on):dnf install procps-ng
[root@6ccffd0f6421 /]# dnf install procps-ngCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
ps -efcommand to list current processes:ps -ef
# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 12:55 pts/0 00:00:00 /bin/bash root 31 1 0 13:07 pts/0 00:00:00 ps -efCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enter
exitto exit the container and return to the host:exit
# exitCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all containers:
podman ps
$ podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1984555a2c27 registry.redhat.io/ubi10/ubi:latest /bin/bash 21 minutes ago Exited (0) 21 minutes ago myubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that the container is in Exited status.
5.4. Building a container Copy linkLink copied to clipboard!
Buildah is the primary tool for building containers in the Red Hat Enterprise Linux, and you can use it with Podman to manage and run the containers you build.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Install Container Tools: Ensure the necessary container tools are installed on your RHEL system. The container-tools module provides Buildah, Podman, and Skopeo.
sudo dnf install container-tools
$ sudo dnf install container-toolsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a Containerfile: A Containerfile defines the instructions for building your container image. This file specifies the base image, any software to install, configurations to apply, and the application to run. For example:
FROM registry.redhat.io/rhel10/rhel-minimal RUN dnf -y update && dnf -y install httpd COPY index.html /var/www/html/ EXPOSE 80 CMD ["httpd", "-DFOREGROUND"]
FROM registry.redhat.io/rhel10/rhel-minimal RUN dnf -y update && dnf -y install httpd COPY index.html /var/www/html/ EXPOSE 80 CMD ["httpd", "-DFOREGROUND"]Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build the container image with Buildah: Use
buildah bud(orpodman build) to build the image after you navigate to the directory containing your Container file.cd /<path_to_container_file> buildah bud -t your_image_name:tag .
$ cd /<path_to_container_file> $ buildah bud -t your_image_name:tag .Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
your_image_name: The name for your image. -
tag: The tag for your image (e.g., latest, 1.0). -
.: Indicates that the Containerfile is in the current directory.
-
Run the container: After you build the image, you can run a container from it using the
podman runcommand.podman run -d -p 8080:80 my-web-app
$ podman run -d -p 8080:80 my-web-appCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
-d: Runs the container in detached mode (in the background). -
-p 8080:80: Maps port 8080 on the host to port 80 inside the container. my-web-app: The name of the image to run.- The heredocs syntax in container buildings
You can use the
heredocsyntax in Containerfile, with a Red Hat Enterprise Linux base image, ensuring you enableBuildKit. If the commands containheredocsyntax, the Containerfile considers the next lines, until the line only contains a heredoc delimiter, as part of the same command. You can embed multi-line strings directly within instructions likeRUNorCOPYin Containerfile usingheredocs. This is especially useful with RHEL-based images, as it removes the need to create separate script files for simple tasks and thus improves readability and maintainability.For Example, a common use case is running multiple shell commands in a single
RUNinstruction to create a single image layer, avoiding the&& \syntax:
-
-
RUN <<EOF: The<<signals the start of the heredoc, andEOFis the user-defined delimiter. -
The lines between the
<<EOFand the finalEOFare treated as a single script executed by the shell. -
The entire block is a single
RUNinstruction, which is more efficient and easier to read.
5.5. Listing containers Copy linkLink copied to clipboard!
Use the podman ps command to list the running containers on the system.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Run the container based on
registry.redhat.io/rhel10/support-toolsimage:podman run -d registry.redhat.io/rhel8/support-tools
$ podman run -d registry.redhat.io/rhel8/support-toolsCopy to Clipboard Copied! Toggle word wrap Toggle overflow List all containers:
To list all running containers:
podman ps
$ podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 74b1da000a11 rhel10/support-tools /usr/bin/bash 2 minutes ago Up About a minute musing_brownCopy to Clipboard Copied! Toggle word wrap Toggle overflow To list all containers, running or stopped:
podman ps -a
$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES IS INFRA d65aecc325a4 ubi10/ubi /bin/bash 3 secs ago Exited (0) 5 secs ago peaceful_hopper false 74b1da000a11 rhel10/support-tools /usr/bin/bash 2 mins ago Up About a minute musing_brown falseCopy to Clipboard Copied! Toggle word wrap Toggle overflow If you do not remove containers that are not running, by using the
--rmoption, you can restart them.For more information, see the
podman-images(1)man page on your system.
5.6. Starting containers Copy linkLink copied to clipboard!
If you run the container and then stop it, and not remove it, the container is stored on your local system ready to run again. You can use the podman start command to re-run the containers. You can specify the containers by their container ID or name.
Prerequisites
-
The
container-toolsmeta-package is installed. - At least one container has been stopped.
Procedure
Start the
myubicontainer:In the non interactive mode:
podman start myubi
$ podman start myubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, you can use
podman start 1984555a2c27.In the interactive mode, use
-a(--attach) and-i(--interactive) options to work with container bash shell:podman start -a -i myubi
$ podman start -a -i myubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, you can use
podman start -a -i 1984555a2c27.
Enter
exitto exit the container and return to the host:exit
[root@6ccffd0f6421 /]# exitCopy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-start(1)man page on your system.
5.7. Inspecting containers from the host Copy linkLink copied to clipboard!
Use the podman inspect command to inspect the metadata of an existing container in a JSON format. You can specify the containers by their container ID or name.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Inspect the container defined by ID 64ad95327c74:
To get all metadata:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To get particular items from the JSON file, for example, the
StartedAttimestamp:podman inspect --format='{{.State.StartedAt}}' 64ad95327c74$ podman inspect --format='{{.State.StartedAt}}' 64ad95327c74 2021-03-02 11:23:54.945071961 +0100 CETCopy to Clipboard Copied! Toggle word wrap Toggle overflow The information is stored in a hierarchy. To see the container
StartedAttimestamp (StartedAtis underState), use the--formatoption and the container ID or name.Examples of other items you might want to inspect include:
-
.Pathto see the command run with the container -
.Argsarguments to the command -
.Config.ExposedPortsTCP or UDP ports exposed from the container -
.State.Pidto see the process id of the container .HostConfig.PortBindingsport mapping from container to hostFor more information, see the
podman-inspect(1)man page on your system.
5.8. Mounting directory on localhost to the container Copy linkLink copied to clipboard!
You can make log messages from inside a container available to the host system by mounting the host /dev/log device inside the container.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Run the container named
log_testand mount the host/dev/logdevice inside the container:podman run --name="log_test" -v /dev/log:/dev/log --rm \ registry.redhat.io/ubi10/ubi logger "Testing logging to the host"
# podman run --name="log_test" -v /dev/log:/dev/log --rm \ registry.redhat.io/ubi10/ubi logger "Testing logging to the host"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
journalctlutility to display logs:journalctl -b | grep Testing
# journalctl -b | grep Testing Dec 09 16:55:00 localhost.localdomain root[14634]: Testing logging to the hostCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
--rmoption removes the container when it exits.
5.9. Mounting a container filesystem Copy linkLink copied to clipboard!
Use the podman mount command to mount a working container root filesystem in a location accessible from the host.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Run the container named
mysyslog:podman run -d --name=mysyslog registry.redhat.io/rhel10/support-tools
# podman run -d --name=mysyslog registry.redhat.io/rhel10/support-toolsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all containers:
podman ps -a
# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c56ef6a256f8 registry.redhat.io/rhel10/support-tools:latest usr/bin/bash 20 minutes ago Up 20 minutes ago mysyslogCopy to Clipboard Copied! Toggle word wrap Toggle overflow Mount the
mysyslogcontainer:podman mount mysyslog
# podman mount mysyslog /var/lib/containers/storage/overlay/990b5c6ddcdeed4bde7b245885ce4544c553d108310e2b797d7be46750894719/mergedCopy to Clipboard Copied! Toggle word wrap Toggle overflow Display the content of the mount point using
lscommand:ls /var/lib/containers/storage/overlay/990b5c6ddcdeed4bde7b245885ce4544c553d108310e2b797d7be46750894719/merged
# ls /var/lib/containers/storage/overlay/990b5c6ddcdeed4bde7b245885ce4544c553d108310e2b797d7be46750894719/merged bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr varCopy to Clipboard Copied! Toggle word wrap Toggle overflow Display the OS version:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-mount(1)man page on your system.
5.10. Running a service as a daemon with a static IP Copy linkLink copied to clipboard!
The following example runs the support-tools service as a daemon process in the background. The --ip option sets the container network interface to a particular IP address (for example, 10.88.0.44). After that, you can run the podman inspect command to check that you set the IP address properly.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Set the container network interface to the IP address 10.88.0.44:
podman run -d --ip=10.88.0.44 registry.access.redhat.com/rhel10/support-tools
# podman run -d --ip=10.88.0.44 registry.access.redhat.com/rhel10/support-tools efde5f0a8c723f70dd5cb5dc3d5039df3b962fae65575b08662e0d5b5f9fbe85Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check that the IP address is set properly:
podman inspect efde5f0a8c723 | grep 10.88.0.44
# podman inspect efde5f0a8c723 | grep 10.88.0.44 "IPAddress": "10.88.0.44",Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-inspect(1)andpodman-run(1)man pages on your system.
5.11. Executing commands inside a running container Copy linkLink copied to clipboard!
Use the podman exec command to execute a command in a running container and investigate that container. The reason for using the podman exec command instead of podman run command is that you can investigate the running container without interrupting the container activity.
Prerequisites
-
The
container-toolsmeta-package is installed. - The container is running.
Procedure
Execute the
rpm -qacommand inside themy-support-toolscontainer to list all installed packages:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Execute a
/bin/bashcommand in themy-support-toolscontainer:podman exec -it my-support-tools /bin/bash
$ podman exec -it my-support-tools /bin/bashCopy to Clipboard Copied! Toggle word wrap Toggle overflow Install the
procps-ngpackage containing a set of system utilities (for exampleps,top,uptime, and so on):dnf install procps-ng
# dnf install procps-ngCopy to Clipboard Copied! Toggle word wrap Toggle overflow Inspect the container:
To list every process on the system:
ps -ef
# ps -ef UID PID PPID C STIME TTY TIME CMD root 8 0 0 11:07 pts/0 00:00:00 /bin/bash root 47 8 0 11:13 pts/0 00:00:00 ps -efCopy to Clipboard Copied! Toggle word wrap Toggle overflow To display file system disk space usage:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To display system information:
uname -r
# uname -r 6.13.4-200.fc41.x86_64Copy to Clipboard Copied! Toggle word wrap Toggle overflow To display amount of free and used memory in megabytes:
free --mega
# free --mega total used free shared buff/cache available Mem: 2818 615 1183 12 1020 1957 Swap: 3124 0 3124Copy to Clipboard Copied! Toggle word wrap Toggle overflow
5.12. Sharing files between two containers Copy linkLink copied to clipboard!
You can use volumes to persist data in containers even when a container is deleted. Volumes can be used for sharing data among multiple containers. The volume is a folder which is stored on the host machine. The volume can be shared between the container and the host.
Main advantages are:
- Volumes can be shared among the containers.
- Volumes are easier to back up or migrate.
- Volumes do not increase the size of the containers.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create a volume:
podman volume create hostvolume
$ podman volume create hostvolumeCopy to Clipboard Copied! Toggle word wrap Toggle overflow Display information about the volume:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Notice that it creates a volume in the volumes directory. You can save the mount point path to the variable for easier manipulation:
$ mntPoint=$(podman volume inspect hostvolume --format {{.Mountpoint}}).Notice that if you run
sudo podman volume create hostvolume, then the mount point changes to/var/lib/containers/storage/volumes/hostvolume/_data.Create a text file inside the directory using the path that is stored in the
mntPointvariable:echo "Hello from host" >> $mntPoint/host.txt
$ echo "Hello from host" >> $mntPoint/host.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow List all files in the directory defined by the
mntPointvariable:ls $mntPoint/
$ ls $mntPoint/ host.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the container named
myubi1and map the directory defined by thehostvolumevolume name on the host to the/containervolume1directory on the container:podman run -it --name myubi1 -v hostvolume:/containervolume1 registry.access.redhat.com/ubi10/ubi /bin/bash
$ podman run -it --name myubi1 -v hostvolume:/containervolume1 registry.access.redhat.com/ubi10/ubi /bin/bashCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that if you use the volume path defined by the
mntPointvariable (-v $mntPoint:/containervolume1), data can be lost when runningpodman volume prunecommand, which removes unused volumes. Always use-v hostvolume_name:/containervolume_name.List the files in the shared volume on the container:
ls /containervolume1
# ls /containervolume1 host.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can see the
host.txtfile which you created on the host.Create a text file inside the
/containervolume1directory:echo "Hello from container 1" >> /containervolume1/container1.txt
# echo "Hello from container 1" >> /containervolume1/container1.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Detach from the container with
CTRL+pandCTRL+q. List the files in the shared volume on the host, you should see two files:
ls $mntPoint
$ ls $mntPoint container1.rxt host.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow At this point, you are sharing files between the container and host. To share files between two containers, run another container named
myubi2.Run the container named
myubi2and map the directory defined by thehostvolumevolume name on the host to the/containervolume2directory on the container:podman run -it --name myubi2 -v hostvolume:/containervolume2 registry.access.redhat.com/ubi10/ubi /bin/bash
$ podman run -it --name myubi2 -v hostvolume:/containervolume2 registry.access.redhat.com/ubi10/ubi /bin/bashCopy to Clipboard Copied! Toggle word wrap Toggle overflow List the files in the shared volume on the container:
ls /containervolume2
# ls /containervolume2 container1.txt host.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can see the
host.txtfile which you created on the host andcontainer1.txtwhich you created inside themyubi1container.Create a text file inside the
/containervolume2directory:echo "Hello from container 2" >> /containervolume2/container2.txt
# echo "Hello from container 2" >> /containervolume2/container2.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Detach from the container with
CTRL+pandCTRL+q. List the files in the shared volume on the host, you should see three files:
ls $mntPoint
$ ls $mntPoint container1.rxt container2.txt host.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-volume(1)man page on your system.
5.13. Exporting and importing containers Copy linkLink copied to clipboard!
You can use the podman export command to export the file system of a running container to a tarball on your local machine. For example, if you have a large container that you use infrequently or one that you want to save a snapshot of in order to revert back to it later, you can use the podman export command to export a current snapshot of your running container into a tarball.
You can use the podman import command to import a tarball and save it as a filesystem image. Then you can run this filesystem image or you can use it as a layer for other images.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Run the
myubicontainer based on theregistry.access.redhat.com/ubi10/ubiimage:podman run -dt --name=myubi registry.access.redhat.com/10/ubi
$ podman run -dt --name=myubi registry.access.redhat.com/10/ubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all containers:
podman ps -a
$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a6a6d4896142 registry.access.redhat.com/10:latest /bin/bash 7 seconds ago Up 7 seconds ago myubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow Attach to the
myubicontainer:podman attach myubi
$ podman attach myubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a file named
testfile:echo "hello" > testfile
[root@a6a6d4896142 /]# echo "hello" > testfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Detach from the container with
CTRL+pandCTRL+q. Export the file system of the
myubias amyubi-container.taron the local machine:podman export -o myubi.tar a6a6d4896142
$ podman export -o myubi.tar a6a6d4896142Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List the current directory content:
ls -l
$ ls -l -rw-r--r--. 1 user user 210885120 Apr 6 10:50 myubi-container.tar ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Create a
myubi-containerdirectory, extract all files from themyubi-container.tararchive. List a content of themyubi-directoryin a tree-like format:Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that the
myubi-container.tarcontains the container file system.Import the
myubi.tarand saves it as a filesystem image:Copy to Clipboard Copied! Toggle word wrap Toggle overflow List all images:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/myubi-imported latest c296689a17da 51 seconds ago 211 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow Display the content of the
testfilefile:podman run -it --name=myubi-imported docker.io/library/myubi-imported cat testfile hello
$ podman run -it --name=myubi-imported docker.io/library/myubi-imported cat testfile helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-export (1)andpodman-import(1)man pages on your system.
5.14. Stopping containers Copy linkLink copied to clipboard!
Use the podman stop command to stop a running container. You can specify the containers by their container ID or name.
Prerequisites
-
The
container-toolsmeta-package is installed. - At least one container is running.
Procedure
Stop the
myubicontainer:By using the container name:
podman stop myubi
$ podman stop myubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow By using the container ID:
podman stop 1984555a2c27
$ podman stop 1984555a2c27Copy to Clipboard Copied! Toggle word wrap Toggle overflow To stop a running container that is attached to a terminal session, you can enter the
exitcommand inside the container.The
podman stopcommand sends a SIGTERM signal to terminate a running container. If the container does not stop after a defined period (10 seconds by default), Podman sends a SIGKILL signal.You can also use the
podman killcommand to kill a container (SIGKILL) or send a different signal to a container. Here is an example of sending a SIGHUP signal to a container (if supported by the application, a SIGHUP causes the application to re-read its configuration files):
*podman kill --signal="SIGHUP" 74b1da000a11*
# *podman kill --signal="SIGHUP" 74b1da000a11*
74b1da000a114015886c557deec8bed9dfb80c888097aa83f30ca4074ff55fb2
+ For more information, see the podman-stop(1) and podman-kill(1) man pages on your system.
5.15. Removing containers Copy linkLink copied to clipboard!
Use the podman rm command to remove containers. You can specify containers with the container ID or name.
Prerequisites
-
The
container-toolsmeta-package is installed. - At least one container has been stopped.
Procedure
List all containers, running or stopped:
podman ps -a
$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES IS INFRA d65aecc325a4 ubi10/ubi /bin/bash 3 secs ago Exited (0) 5 secs ago peaceful_hopper false 74b1da000a11 rhel10/support-tools usr/bin/bash 2 mins ago Up About a minute musing_brown falseCopy to Clipboard Copied! Toggle word wrap Toggle overflow Remove the containers:
To remove the
peaceful_hoppercontainer:podman rm peaceful_hopper
$ podman rm peaceful_hopperCopy to Clipboard Copied! Toggle word wrap Toggle overflow Notice that the
peaceful_hoppercontainer was in Exited status, which means it was stopped and it can be removed immediately.To remove the
musing_browncontainer, first stop the container and then remove it:podman stop musing_brown podman rm musing_brown
$ podman stop musing_brown $ podman rm musing_brownCopy to Clipboard Copied! Toggle word wrap Toggle overflow To remove multiple containers:
podman rm clever_yonath furious_shockley
$ podman rm clever_yonath furious_shockleyCopy to Clipboard Copied! Toggle word wrap Toggle overflow To remove all containers from your local system:
podman rm -a
$ podman rm -aCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
-
List all images by using the
podman ps -acommand to verify that containers were removed.
5.16. Creating SELinux policies for containers Copy linkLink copied to clipboard!
To generate SELinux policies for containers, use the UDICA tool. For more information, see Introduction to the udica SELinux policy generator.
5.17. Configuring pre-execution hooks in Podman Copy linkLink copied to clipboard!
You can create plugin scripts to define a fine-control over container operations, especially blocking unauthorized actions, for example pulling, running, or listing container images.
The file /etc/containers/podman_preexec_hooks.txt must be created by an administrator and can be empty. If the /etc/containers/podman_preexec_hooks.txt does not exist, the plugin scripts will not be executed.
The following rules apply to the plugin scripts:
- Have to be root-owned and not writable.
-
Have to be located in the
/usr/libexec/podman/pre-exec-hooksand/etc/containers/pre-exec-hooksdirectories. - Execute in sequentially and alphanumeric order.
-
If all plugin scripts return zero value, then the
podmancommand is executed. -
If any of the plugin scripts return a non-zero value, it indicates a failure. The
podmancommand exits and returns the non-zero value of the first-failed script. Red Hat recommends to use the following naming convention to execute the scripts in the correct order:
DDD_name.lang, where:-
The
DDDis the decimal number indicating the order of script execution. Use one or two leading zeros if necessary. -
The
nameis the name of the plugin script. -
The
lang(optional) is the file extension for the given programming language. For example, the name of the plugin script can be:001-check-groups.sh.
-
The
The plugin scripts are valid at the time of creation. Containers created before plugin scripts are not affected.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create the script plugin named
001-check-groups.sh. For example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - The script checks if a user is in a specified group.
-
The
USERandGROUPare environment variables set by Podman. -
Exit code provided by the
001-check-groups.shscript would be provided to thepodmanbinary. -
The
podmancommand exits and returns the non-zero value of the first-failed script.
Verification
Check if the
001-check-groups.shscript works correctly:podman run image
$ podman run image ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the user is not in the correct group, the following error appears:
external preexec hook /etc/containers/pre-exec-hooks/001-check-groups.sh failed
external preexec hook /etc/containers/pre-exec-hooks/001-check-groups.sh failedCopy to Clipboard Copied! Toggle word wrap Toggle overflow
5.18. Debugging applications in containers Copy linkLink copied to clipboard!
You can use various command-line tools tailored to different aspects of troubleshooting. For more information, see Debugging applications in containers.
Chapter 6. Introduction to reproducible container builds Copy linkLink copied to clipboard!
Red Hat Enterprise Linux (RHEL) now supports reproducible container builds using the Red Hat tools Podman and Buildah. This new feature reduces changes in images when users build them with the same inputs but at different times. Fewer changes between images can decrease the amount of data you need to pull from a registry when moving from one version of an image to a newer version of that image. Reproducible container builds are crucial for ensuring supply chain security, facilitating reliable software deployment, and facilitating effective debugging.
Previously, the escalating size of container images and increased customer apprehension regarding update payload sizes amplify the existing challenges and limitations associated with tarball creation. In systems like Konflux, each Git commit generates new tarballs, which necessitates a complete re-download of the entire image. Factors such as mtime changes mean that even when users install the same RPMs, storage requirements double, despite no alteration in the underlying data. This not only burdens registry storage but also forces clients to pull a new layer, even if no changes have occurred. This situation further exacerbates problems in environments like rhel-bootc and RHEL AI, which prioritize faster updates.
6.1. Benefits of reproducible container builds Copy linkLink copied to clipboard!
Reproducible builds for RHEL containers reduce registry storage, create smaller update payloads, and enable faster downloads by ensuring the image layers remain consistent when the source code and build environment are unchanged. This process maximizes the efficiency of layer caching, preventing the redundant storage and transfer of identical data. The notable benefits of reproducible container builds are:
- Reduced registry storage: When an image is updated, only changed layers are stored. Reproducible builds ensure identical images from the same source code by preventing non-deterministic factors (timestamps, file order, metadata) from causing changes, thus avoiding additional storage.
- Efficient and smaller update payloads: For container minor updates, for example, security patches, only the changed layer needs to be downloaded, not the whole image. Reproducible builds also ensure that only affected layers change with source updates, unlike non-reproducible builds where small code changes can alter multiple layers.
- Faster downloads: Container reproducible builds optimize both build systems and end users by enabling faster downloads through efficient caching, and reduced network traffic.
6.2. Impact of reproducible container builds on different environments Copy linkLink copied to clipboard!
Reproducible container builds on RHEL ensure consistent, identical container images regardless of build time or location. The impact of reproducible container builds on diffrent environments are:
Konflux
- Enhanced software supply chain integrity: Reproducible container builds enhance Konflux’s mission of delivering a secure and transparent software supply chain. Konflux uses reproducible builds to verify that a built container image derives exactly from its source code. Any third party can rebuild the container from the same inputs and verify that the output is bit-for-bit identical. Also, RHEL reproducible container builds protect against "in-transit" vulnerabilities, where an attacker can compromise a distribution mirror or inject malicious code into the build process. Konflux can prove that the released binary matches its source, mitigating attacks on its own build infrastructure.
- Improved compliance and transparency: Konflux enforces SLSA security policies. It verifies the origin and provenance of reproducible RHEL images, simplifying compliance. Konflux uses Tekton Chains to create an immutable, signed attestation that documents the entire build process. RHEL’s reproducible container builds add a foundational layer of trust to this attestation by ensuring the base image is trustworthy and verifiably built.
- Development and security workflows: Reproducible builds guarantee consistent container image digests across multiple runs, simplifying testing and debugging. Konflux leverages this to efficiently scan and update vulnerable packages in RHEL containers. Konflux uses verified attestations to automatically block non-compliant builds and enforce security policies without reducing flexibility.
Bootc
- Verifiable supply chain and enhanced security: Reproducible RHEL container builds enhance rhel-bootc by creating a more secure, reliable, and transparent build process for bootable OS images. You can verify that a specific bootc image was built from its claimed source code, which makes it more difficult for attackers to inject malicious code into a container image by compromising a build pipeline.
- Streamlined CI/CD and GitOps Workflows: You can use reproducibility to manage their entire OS configuration and application stack using Git-based workflows (GitOps). A change to the Containerfile, guarantees a consistent bootable image across all environments. Reproducible builds form a cornerstone of automated CI/CD pipelines.
RHEL AI
- Reproducible container builds are critical for RHEL AI because they provide the foundational consistency, security, and efficiency AI model development and deployment need. RHEL AI delivers a bootable container image, which means it manages the operating system itself as a container artifact. Reproducibility ensures that this base AI environment is always consistent and trustworthy.
6.3. Achieving reproducibility in RHEL container tools Copy linkLink copied to clipboard!
RHEL container tools provide a standardized, daemonless, and scriptable workflow using a suite of tools like Buildah, Podman and Skopeo to achieve reproducibility. This approach ensures that a container built once can run consistently anywhere, addressing potential issues with dependencies, environments, and versioning.
Buildah:
RHEL Buildah achieves reproducible container builds by providing granular control over the build process. It offers specific options to mitigate sources of non-determinism, such as unstable tags, filesystem metadata, and host-dependent data. The Buildah features for reproducible builds are:
Fixed timestamps: Timestamps cause major irreproducibility. By default, file creation and modification times reflect when someone adds a file to a container layer, which is never the same twice. Buildah allows you to zero out these timestamps or set them to a specific, fixed value.
-
-–rewrite-timestamp: This option timestamps the contents of layers to be no later than the--source-date-epoch. Also, controls the created timestamp of an image and the timestamps of files within its layers, primarily to achieve deterministic builds. -
--source-date-epoch: This option is more flexible option than the older--timestampoption, allowing you to define a specific, reproducible timestamp for all files in the image layer. It affects creation and history dates in image metadata. You can set it by using CLI flag, environment variable, or as a build-arg. When the flag is set, declared ARGs are exposed in the environment forRUNinstructions and get static hostname. Also, the container ID field is cleared in the committed image.
-
Podman:
The podman build command, while the user-facing interface, delegates the actual image creation to the Buildah library. This means that Podman achieves reproducible container builds by leveraging the same core features as Buildah, with a focus on controlling sources of non-determinism during the build process.
The Podman commands also accept the -–rewrite-timestamp and --source-date-epoch options. Additionally, the --no-cache option instructs Podman to disregard its local cache and perform a fresh build. Using this option helps verify that your container image can be reliably ruced from scratch.
Skopeo:
Skopeo achieves reproducible container builds by referencing immutable image digests instead of mutable tags. Skopeo primarily transports and manages images, while other tools like Buildah handle the actual reproducible image creation.
Using the --source-date-epoch and --rewrite-timestamp options can improve build reproducibility. However, complete reproducibility is not guaranteed. Content added from other images with the COPY instructions’s --from option, accessed through the RUN instruction’s --mount=from= option, or downloaded using the ADD instruction can change if you reference an image tag that later moves, or if the content at the specified URL changes.
6.4. Working with reproducible container builds Copy linkLink copied to clipboard!
You can build a reproducible container image with -–source-date-epoch and -–rewrite-timestamp options, adding ARG SOURCE_DATE_EPOCH to the ContainerFile.
Procedure
To set these options when running your
Buildahcommand. For example, to build an image from a Containerfile and force all timestamps to a specific point in time:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the
podman buildcommand with a consistent timestamp to create the reproducible image:Set a consistent timestamp using the last Git commit date
# Set a consistent timestamp using the last Git commit date export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build the image with the specified timestamp:
podman build --source-date-epoch=${SOURCE_DATE_EPOCH} --rewrite-timestamp -t my-reproducible-app .podman build --source-date-epoch=${SOURCE_DATE_EPOCH} --rewrite-timestamp -t my-reproducible-app .Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
After building, run the reproducible command again. If the build is truly reproducible, the
buildah inspectcommand should show the same image digest.buildah bud --build-arg --source-date-epoch=${SOURCE_DATE_EPOCH} \ --rewrite-timestamp \ -f Containerfile \ -t my-reproducible-image-2 .buildah bud --build-arg --source-date-epoch=${SOURCE_DATE_EPOCH} \ --rewrite-timestamp \ -f Containerfile \ -t my-reproducible-image-2 .Copy to Clipboard Copied! Toggle word wrap Toggle overflow Compare the digests:
buildah inspect --format '{{.Digest}}' my-reproducible-image buildah inspect --format '{{.Digest}}' my-reproducible-image-2buildah inspect --format '{{.Digest}}' my-reproducible-image buildah inspect --format '{{.Digest}}' my-reproducible-image-2Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Chapter 7. Adding software to a UBI container Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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 Copy linkLink copied to clipboard!
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.
NoteIt could take several hours after a container image is released for its associated source container to become available.
For more information, see the
skopeo-copy (1)andskopeo-inspect(1)man pages on your system.
Chapter 8. Working with pods Copy linkLink copied to clipboard!
Containers are the smallest unit that you can manage with Podman, Skopeo and Buildah container tools. A Podman pod is a group of one or more containers. The Pod concept was introduced by Kubernetes. Podman pods are similar to the Kubernetes definition. Pods are the smallest compute units that you can create, deploy, and manage in OpenShift or Kubernetes environments. Every Podman pod includes an infra container. This container holds the namespaces associated with the pod and allows Podman to connect other containers to the pod. It allows you to start and stop containers within the pod and the pod will stay running. The default infra container on the registry.access.redhat.com/ubi10/pause image.
8.1. Creating pods Copy linkLink copied to clipboard!
You can create a pod with one container.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create an empty pod:
podman pod create --name mypod
$ podman pod create --name mypod 223df6b390b4ea87a090a4b5207f7b9b003187a6960bd37631ae9bc12c433aff The pod is in the initial state Created.Copy to Clipboard Copied! Toggle word wrap Toggle overflow The pod is in the initial state Created.
Optional: List all pods:
podman pod ps
$ podman pod ps POD ID NAME STATUS CREATED # OF CONTAINERS INFRA ID 223df6b390b4 mypod Created Less than a second ago 1 3afdcd93de3eCopy to Clipboard Copied! Toggle word wrap Toggle overflow Notice that the pod has one container in it.
Optional: List all pods and containers associated with them:
podman ps -a --pod
$ podman ps -a --pod CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD 3afdcd93de3e registry.access.redhat.com/ubi10/pause Less than a second ago Created 223df6b390b4-infra 223df6b390b4Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that the pod ID from
podman pscommand matches the pod ID in thepodman pod pscommand. The default infra container is based on theregistry.access.redhat.com/ubi10/pauseimage.Run a container named
myubiin the existing pod namedmypod:podman run -dt --name myubi --pod mypod registry.access.redhat.com/ubi10/ubi /bin/bash
$ podman run -dt --name myubi --pod mypod registry.access.redhat.com/ubi10/ubi /bin/bash 5df5c48fea87860cf75822ceab8370548b04c78be9fc156570949013863ccf71Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all pods:
podman pod ps
$ podman pod ps POD ID NAME STATUS CREATED # OF CONTAINERS INFRA ID 223df6b390b4 mypod Running Less than a second ago 2 3afdcd93de3eCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that the pod has two containers in it.
Optional: List all pods and containers associated with them:
podman ps -a --pod
$ podman ps -a --pod CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD 5df5c48fea87 registry.access.redhat.com/ubi10/ubi:latest /bin/bash Less than a second ago Up Less than a second ago myubi 223df6b390b4 3afdcd93de3e registry.access.redhat.com/ubi10/pause Less than a second ago Up Less than a second ago 223df6b390b4-infra 223df6b390b4Copy to Clipboard Copied! Toggle word wrap Toggle overflow
8.2. Displaying pod information Copy linkLink copied to clipboard!
Learn about how to display pod information.
Prerequisites
-
The
container-toolsmeta-package is installed. - The pod has been created. For details, see section Creating pods.
Procedure
Display active processes running in a pod:
To display the running processes of containers in a pod, enter:
podman pod top mypod
$ podman pod top mypod USER PID PPID %CPU ELAPSED TTY TIME COMMAND 0 1 0 0.000 24.077433518s ? 0s /pause root 1 0 0.000 24.078146025s pts/0 0s /bin/bashCopy to Clipboard Copied! Toggle word wrap Toggle overflow To display a live stream of resource usage stats for containers in one or more pods, enter:
podman pod stats -a --no-stream
$ podman pod stats -a --no-stream ID NAME CPU % MEM USAGE / LIMIT MEM % NET IO BLOCK IO PIDS a9f807ffaacd frosty_hodgkin -- 3.092MB / 16.7GB 0.02% -- / -- -- / -- 2 3b33001239ee sleepy_stallman -- -- / -- -- -- / -- -- / -- --Copy to Clipboard Copied! Toggle word wrap Toggle overflow To display information describing the pod, enter:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can see information about containers in the pod.
For more information, see the
podman-pod-top(1),podman-pod-stats(1), andpodman-pod-inspect(1)man pages on your system.
8.3. Stopping pods Copy linkLink copied to clipboard!
You can stop one or more pods by using the podman pod stop command.
Prerequisites
-
The
container-toolsmeta-package is installed. - The pod has been created. For details, see section Creating pods.
Procedure
Stop the pod
mypod:podman pod stop mypod
$ podman pod stop mypodCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all pods and containers associated with them:
podman ps -a --pod
$ podman ps -a --pod CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD ID PODNAME 5df5c48fea87 registry.redhat.io/ubi10/ubi:latest /bin/bash About a minute ago Exited (0) 7 seconds ago myubi 223df6b390b4 mypod 3afdcd93de3e registry.access.redhat.com/10/pause About a minute ago Exited (0) 7 seconds ago 8a4e6527ac9d-infra 223df6b390b4 mypodCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that the pod
mypodand containermyubiare in "Exited" status.
8.4. Removing pods Copy linkLink copied to clipboard!
You can remove one or more stopped pods and containers by using the podman pod rm command.
Prerequisites
-
The
container-toolsmeta-package is installed. - The pod has been created. For details, see section Creating pods.
- The pod has been stopped. For details, see section Stopping pods.
Procedure
Remove the pod
mypod, type:podman pod rm mypod
$ podman pod rm mypod 223df6b390b4ea87a090a4b5207f7b9b003187a6960bd37631ae9bc12c433affCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that removing the pod automatically removes all containers inside it.
Optional: Check that all containers and pods were removed:
podman ps podman pod ps
$ podman ps $ podman pod psCopy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-pod-rm(1)man page on your system.
Chapter 9. Managing a container network Copy linkLink copied to clipboard!
The chapter provides information about how to communicate among containers.
9.1. Listing container networks Copy linkLink copied to clipboard!
In Podman, there are two network behaviors - rootless and rootful:
- Rootless networking - the network is setup automatically, the container does not have an IP address.
- Rootful networking - the container has an IP address.
Prerequisites
The container-tools meta-package is installed.
Procedure
List all networks as a root user:
podman network ls
# podman network ls NETWORK ID NAME VERSION PLUGINS 2f259bab93aa podman 0.4.0 bridge,portmap,firewall,tuningCopy to Clipboard Copied! Toggle word wrap Toggle overflow - By default, Podman provides a bridged network.
List of networks for a rootless user is the same as for a rootful user.
For more information, see the
podman-network-ls(1)man page on your system.
9.2. Inspecting a network Copy linkLink copied to clipboard!
Display the IP range, enabled plugins, type of network, and so on, for a specified network listed by the podman network ls command.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Inspect the default
podmannetwork:Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can see the IP range, enabled plugins, type of network, and other network settings.
For more information, see the
podman-network-inspect(1)man page on your system.
9.3. Creating a network Copy linkLink copied to clipboard!
Use the podman network create command to create a new network. By default, Podman creates an external network. You can create an internal network using the podman network create --internal command. Containers in an internal network can communicate with other containers on the host, but cannot connect to the network outside of the host nor be reached from it.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create the external network named
mynet:podman network create mynet
# podman network create mynet /etc/cni/net.d/mynet.conflistCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
List all networks:
podman network ls
# podman network ls NETWORK ID NAME VERSION PLUGINS 2f259bab93aa podman 0.4.0 bridge,portmap,firewall,tuning 11c844f95e28 mynet 0.4.0 bridge,portmap,firewall,tuning,dnsnameCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can see the created
mynetnetwork and defaultpodmannetwork.
Beginning with Podman 4.0, the DNS plugin is enabled by default if you create a new external network by using the podman network create command.
Refer to podman-network-create(1) man page on your system for more information.
9.4. Connecting a container to a network Copy linkLink copied to clipboard!
Use the podman network connect command to connect the container to the network.
Prerequisites
-
The
container-toolsmeta-package is installed. -
A network has been created by using the
podman network createcommand. - A container has been created.
Procedure
Connect a container named
mycontainerto a network namedmynet:podman network connect mynet mycontainer
# podman network connect mynet mycontainerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that the
mycontaineris connected to themynetnetwork:podman inspect --format='{{.NetworkSettings.Networks}}' mycontainer# podman inspect --format='{{.NetworkSettings.Networks}}' mycontainer map[podman:0xc00042ab40 mynet:0xc00042ac60]Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that
mycontaineris connected tomynetandpodmannetworks.
9.5. Disconnecting a container from a network Copy linkLink copied to clipboard!
Use the podman network disconnect command to disconnect the container from the network.
Prerequisites
-
The
container-toolsmeta-package is installed. -
A network has been created by using the
podman network createcommand. - A container is connected to a network.
Procedure
Disconnect the container named
mycontainerfrom the network namedmynet:podman network disconnect mynet mycontainer
# podman network disconnect mynet mycontainerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that the
mycontaineris disconnected from themynetnetwork:podman inspect --format='{{.NetworkSettings.Networks}}' mycontainer# podman inspect --format='{{.NetworkSettings.Networks}}' mycontainer map[podman:0xc000537440]Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that
mycontaineris disconnected from themynetnetwork,mycontaineris only connected to the defaultpodmannetwork.Refer to
podman-network-disconnect(1)man page on your system for more information.
9.6. Removing a network Copy linkLink copied to clipboard!
Use the podman network rm command to remove a specified network.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
List all networks:
podman network ls
# podman network ls NETWORK ID NAME VERSION PLUGINS 2f259bab93aa podman 0.4.0 bridge,portmap,firewall,tuning 11c844f95e28 mynet 0.4.0 bridge,portmap,firewall,tuning,dnsnameCopy to Clipboard Copied! Toggle word wrap Toggle overflow Remove the
mynetnetwork:podman network rm mynet
# podman network rm mynet mynetCopy to Clipboard Copied! Toggle word wrap Toggle overflow
If the removed network has associated containers with it, you have to use the podman network rm -f command to delete containers and pods.
Verification
Check if
mynetnetwork was removed:podman network ls
# podman network ls NETWORK ID NAME VERSION PLUGINS 2f259bab93aa podman 0.4.0 bridge,portmap,firewall,tuningCopy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see
podman-network-rm(1)man page on your system.
9.7. Removing all unused networks Copy linkLink copied to clipboard!
Use the podman network prune to remove all unused networks. An unused network is a network which has no containers connected to it. The podman network prune command does not remove the default podman network.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Remove all unused networks:
podman network prune
# podman network prune WARNING! This will remove all networks not used by at least one container. Are you sure you want to continue? [y/N] yCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that all networks were removed:
podman network ls
# podman network ls NETWORK ID NAME VERSION PLUGINS 2f259bab93aa podman 0.4.0 bridge,portmap,firewall,tuningCopy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-network-prune(1)man page on your system.
Chapter 10. Communicating among containers Copy linkLink copied to clipboard!
Learn about establishing communication between containers, applications, and host systems leveraging port mapping, DNS resolution, or orchestrating communication within pods.
10.1. The network modes and layers Copy linkLink copied to clipboard!
There are several different network modes in Podman:
-
bridge- creates another network on the default bridge network -
container:<id>- uses the same network as the container with<id>id -
host- uses the host network stack -
network-id- uses a user-defined network created by thepodmannetwork create command -
private- creates a new network for the container -
slirp4nets- creates a user network stack withslirp4netns, the default option for rootless containers -
pasta- high performance replacement forslirp4netns. You can usepastabeginning with Podman v4.4.1. -
none- create a network namespace for the container but do not configure network interfaces for it. The container has no network connectivity. -
ns:<path>- path to a network namespace to join
The host mode gives the container full access to local system services such as D-bus, a system for interprocess communication (IPC), and is therefore considered insecure.
10.2. Differences between slirp4netns and pasta Copy linkLink copied to clipboard!
Notable differences of pasta network mode compared to slirp4netns include:
-
pastasupports IPv6 port forwarding. -
pastais more efficient thanslirp4netns. -
pastacopies IP addresses from the host, while slirp4netns uses a predefined IPv4 address. -
pastauses an interface name from the host, while slirp4netns uses tap0 as interface name. -
pastauses the gateway address from the host, whileslirp4netnsdefines its own gateway address and uses NAT.
The default network mode for rootless containers is slirp4netns.
10.3. Setting the network mode Copy linkLink copied to clipboard!
You can use the podman run command with the --network option to select the network mode.
Prerequisites
-
The
container-toolsmodule is installed.
Procedure
Optional: If you want to use the
pastanetwork mode, install thepasstpackage:{PackageManager} install passt$ {PackageManager} install passtCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the container based on the
registry.access.redhat.com/ubi10/ubiimage:podman run --network=<netwok_mode> -d --name=myubi registry.access.redhat.com/ubi9/ubi
$ podman run --network=<netwok_mode> -d --name=myubi registry.access.redhat.com/ubi9/ubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
<netwok_mode>is the required network mode. Alternatively, you can use thedefault_rootless_network_cmdoption in thecontainers.conffile to switch the default network mode.
The default network mode for rootless containers is slirp4netns.
Verification
Verify the setting of the network mode:
podman inspect --format {{.HostConfig.NetworkMode}} myubi$ podman inspect --format {{.HostConfig.NetworkMode}} myubi <netwok_mode>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
10.4. Inspecting a network settings of a container Copy linkLink copied to clipboard!
Use the podman inspect command with the --format option to display individual items from the podman inspect output.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Display the IP address of a container:
podman inspect --format='{{.NetworkSettings.IPAddress}}' <containerName># podman inspect --format='{{.NetworkSettings.IPAddress}}' <containerName>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display all networks to which container is connected:
podman inspect --format='{{.NetworkSettings.Networks}}' <containerName># podman inspect --format='{{.NetworkSettings.Networks}}' <containerName>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display port mappings:
podman inspect --format='{{.NetworkSettings.Ports}}' <containerName># podman inspect --format='{{.NetworkSettings.Ports}}' <containerName>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
10.5. Communicating between a container and an application Copy linkLink copied to clipboard!
You can communicate between a container and an application. An application ports are in either listening or open state. These ports are automatically exposed to the container network, therefore, you can reach those containers using these networks. By default, the web server listens on port 80. Using this procedure, the myubi container communicates with the web-container application.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Start the container named
web-container:podman run -dt --name=web-container docker.io/library/httpd
# podman run -dt --name=web-container docker.io/library/httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow List all containers:
podman ps -a
# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b8c057333513 docker.io/library/httpd:latest httpd-foreground 4 seconds ago Up 5 seconds ago web-containerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Inspect the container and display the IP address:
podman inspect --format='{{.NetworkSettings.IPAddress}}' web-container# podman inspect --format='{{.NetworkSettings.IPAddress}}' web-container 10.88.0.2Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the
myubicontainer and verify that web server is running:podman run -it --name=myubi ubi10/ubi curl 10.88.0.2:80
# podman run -it --name=myubi ubi10/ubi curl 10.88.0.2:80Copy to Clipboard Copied! Toggle word wrap Toggle overflow
10.6. Communicating between a container and a host Copy linkLink copied to clipboard!
By default, the podman network is a bridge network. It means that a network device is bridging a container network to your host network.
Prerequisites
-
The
container-toolsmeta-package is installed. -
The
web-containeris running. For more information, see Communicating between a container and an application.
Procedure
Verify that the bridge is configured:
podman network inspect podman | grep bridge
# podman network inspect podman | grep bridge "type": "bridge"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display the host network configuration:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that the
web-containerhas an IP of thepodman0subnet and the network is bridged to the host.Inspect the
web-containerand display its IP address:podman inspect --format='{{.NetworkSettings.IPAddress}}' web-container# podman inspect --format='{{.NetworkSettings.IPAddress}}' web-container 10.88.0.2Copy to Clipboard Copied! Toggle word wrap Toggle overflow Access the
web-containerdirectly from the host:curl 10.88.0.2:80
$ curl 10.88.0.2:80Copy to Clipboard Copied! Toggle word wrap Toggle overflow
10.7. Communicating between containers using port mapping Copy linkLink copied to clipboard!
The most convenient way to communicate between two containers is to use published ports. Ports can be published in two ways: automatically or manually.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Run the unpublished container:
podman run -dt --name=web1 ubi10/httpd-24
# podman run -dt --name=web1 ubi10/httpd-24Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the automatically published container:
podman run -dt --name=web2 -P ubi10/httpd-24
# podman run -dt --name=web2 -P ubi10/httpd-24Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the manually published container and publish container port 8080:
podman run -dt --name=web3 -p 8888:8080 ubi10/httpd-24
# podman run -dt --name=web3 -p 8888:8080 ubi10/httpd-24Copy to Clipboard Copied! Toggle word wrap Toggle overflow List all containers:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that:
-
Container
web1has no published ports and can be reached only by container network or a bridge. Container
web2has automatically mapped ports 43595 and 42423 to publish the application ports 8080 and 8443, respectively.NoteThe automatic port mapping is possible because the
registry.access.redhat.com/10/httpd-24image has theEXPOSE 8080andEXPOSE 8443commands in the Containerfile.-
Container
web3has a manually published port. The host port 8888 is mapped to the container port 8080.
-
Container
Display the IP addresses of
web1andweb3containers:podman inspect --format='{{.NetworkSettings.IPAddress}}' web1 podman inspect --format='{{.NetworkSettings.IPAddress}}' web3# podman inspect --format='{{.NetworkSettings.IPAddress}}' web1 # podman inspect --format='{{.NetworkSettings.IPAddress}}' web3Copy to Clipboard Copied! Toggle word wrap Toggle overflow Reach
web1container using <IP>:<port> notation:curl 10.88.0.2:8080
# curl 10.88.0.2:8080 ... <title>Test Page for the HTTP Server on Red Hat Enterprise Linux</title> ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Reach
web2container using localhost:<port> notation:curl localhost:43595
# curl localhost:43595 ... <title>Test Page for the HTTP Server on Red Hat Enterprise Linux</title> ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Reach
web3container using <IP>:<port> notation:curl 10.88.0.4:8080
# curl 10.88.0.4:8080 ... <title>Test Page for the HTTP Server on Red Hat Enterprise Linux</title> ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow
10.8. Communicating between containers using DNS Copy linkLink copied to clipboard!
When a DNS plugin is enabled, use a container name to address containers.
Prerequisites
-
The
container-toolsmeta-package is installed. -
A network with the enabled DNS plugin has been created by using the
podman network createcommand.
Procedure
Run a
receivercontainer attached to themynetnetwork:podman run -d --net mynet --name receiver ubi9 sleep 3000
# podman run -d --net mynet --name receiver ubi9 sleep 3000Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run a
sendercontainer and reach thereceivercontainer by its name:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Exit using the
CTRL+C.You can see that the
sendercontainer can ping thereceivercontainer using its name.
10.9. Communicating between two containers in a pod Copy linkLink copied to clipboard!
All containers in the same pod share the IP addresses, MAC addresses and port mappings. You can communicate between containers in the same pod using localhost:port notation.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create a pod named
web-pod:podman pod create --name=web-pod
$ podman pod create --name=web-podCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the web container named
web-containerin the pod:podman container run -d --pod web-pod --name=web-container docker.io/library/httpd
$ podman container run -d --pod web-pod --name=web-container docker.io/library/httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow List all pods and containers associated with them:
podman ps --pod
$ podman ps --pod CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD ID PODNAME 58653cf0cf09 k8s.gcr.io/pause:3.5 4 minutes ago Up 3 minutes ago 4e61a300c194-infra 4e61a300c194 web-pod b3f4255afdb3 docker.io/library/httpd:latest httpd-foreground 3 minutes ago Up 3 minutes ago web-container 4e61a300c194 web-podCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the container in the
web-podbased on the docker.io/library/fedora image:podman container run -it --rm --pod web-pod docker.io/library/fedora curl localhost
$ podman container run -it --rm --pod web-pod docker.io/library/fedora curl localhostCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that the container can reach the
web-container.
10.10. Communicating in a pod Copy linkLink copied to clipboard!
You must publish the ports for the container in a pod when a pod is created.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create a pod named
web-pod:podman pod create --name=web-pod-publish -p 80:80
# podman pod create --name=web-pod-publish -p 80:80Copy to Clipboard Copied! Toggle word wrap Toggle overflow List all pods:
podman pod ls
# podman pod ls POD ID NAME STATUS CREATED INFRA ID # OF CONTAINERS 26fe5de43ab3 publish-pod Created 5 seconds ago 7de09076d2b3 1Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the web container named
web-containerinside theweb-pod:podman container run -d --pod web-pod-publish --name=web-container docker.io/library/httpd
# podman container run -d --pod web-pod-publish --name=web-container docker.io/library/httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow List containers
podman ps
# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7de09076d2b3 k8s.gcr.io/pause:3.5 About a minute ago Up 23 seconds ago 0.0.0.0:80->80/tcp 26fe5de43ab3-infra 088befb90e59 docker.io/library/httpd httpd-foreground 23 seconds ago Up 23 seconds ago 0.0.0.0:80->80/tcp web-containerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the
web-containercan be reached:curl localhost:80
$ curl localhost:80Copy to Clipboard Copied! Toggle word wrap Toggle overflow
10.11. Attaching a pod to the container network Copy linkLink copied to clipboard!
Attach containers in pod to the network during the pod creation.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create a network named
pod-net:podman network create pod-net
# podman network create pod-net /etc/cni/net.d/pod-net.conflistCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a pod
web-pod:podman pod create --net pod-net --name web-pod
# podman pod create --net pod-net --name web-podCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run a container named
web-containerinside theweb-pod:podman run -d --pod webt-pod --name=web-container docker.io/library/httpd
# podman run -d --pod webt-pod --name=web-container docker.io/library/httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Display the pods the containers are associated with:
podman ps -p
# podman ps -p CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD ID PODNAME b7d6871d018c registry.access.redhat.com/ubi10/pause:latest 9 minutes ago Up 6 minutes ago a8e7360326ba-infra a8e7360326ba web-pod 645835585e24 docker.io/library/httpd:latest httpd-foreground 6 minutes ago Up 6 minutes ago web-container a8e7360326ba web-podCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Show all networks connected to the container:
podman ps --format="{{.Networks}}"# podman ps --format="{{.Networks}}" pod-netCopy to Clipboard Copied! Toggle word wrap Toggle overflow
10.12. Setting HTTP Proxy variables for Podman Copy linkLink copied to clipboard!
To pull images behind a proxy server, you must set HTTP Proxy variables for Podman. Podman reads the environment variable HTTP_PROXY to ascertain the HTTP Proxy information. HTTP proxy information can be configured as an environment variable or under /etc/profile.d.
Procedure
Set proxy variables for Podman. For example:
Unauthenticated proxy:
cat /etc/profile.d/unauthenticated_http_proxy.sh export HTTP_PROXY=http://192.168.0.1:3128 export HTTPS_PROXY=http://192.168.0.1:3128 export NO_PROXY=example.com,172.5.0.0/16
# cat /etc/profile.d/unauthenticated_http_proxy.sh export HTTP_PROXY=http://192.168.0.1:3128 export HTTPS_PROXY=http://192.168.0.1:3128 export NO_PROXY=example.com,172.5.0.0/16Copy to Clipboard Copied! Toggle word wrap Toggle overflow Authenticated proxy:
cat /etc/profile.d/authenticated_http_proxy.sh export HTTP_PROXY=http://USERNAME:PASSWORD@192.168.0.1:3128 export HTTPS_PROXY=http://USERNAME:PASSWORD@192.168.0.1:3128 export NO_PROXY=example.com,172.5.0.0/16
# cat /etc/profile.d/authenticated_http_proxy.sh export HTTP_PROXY=http://USERNAME:PASSWORD@192.168.0.1:3128 export HTTPS_PROXY=http://USERNAME:PASSWORD@192.168.0.1:3128 export NO_PROXY=example.com,172.5.0.0/16Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Chapter 11. Setting container network modes Copy linkLink copied to clipboard!
The chapter provides information about how to set different network modes.
11.1. Running containers with a static IP Copy linkLink copied to clipboard!
The podman run command with the --ip option sets the container network interface to a particular IP address (for example, 10.88.0.44). To verify that you set the IP address correctly, run the podman inspect command.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Set the container network interface to the IP address 10.88.0.44:
podman run -d --name=myubi --ip=10.88.0.44 registry.access.redhat.com/ubi9/ubi
# podman run -d --name=myubi --ip=10.88.0.44 registry.access.redhat.com/ubi9/ubi efde5f0a8c723f70dd5cb5dc3d5039df3b962fae65575b08662e0d5b5f9fbe85Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Check that the IP address is set properly:
podman inspect --format='{{.NetworkSettings.IPAddress}}' myubi# podman inspect --format='{{.NetworkSettings.IPAddress}}' myubi 10.88.0.44Copy to Clipboard Copied! Toggle word wrap Toggle overflow
11.2. Running the DHCP plugin for Netavark using systemd Copy linkLink copied to clipboard!
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Enable the DHCP proxy by using the systemd socket:
systemctl enable --now netavark-dhcp-proxy.socket Created symlink /etc/systemd/system/sockets.target.wants/netavark-dhcp-proxy.socket → /usr/lib/systemd/system/netavark-dhcp-proxy.socket.
systemctl enable --now netavark-dhcp-proxy.socket Created symlink /etc/systemd/system/sockets.target.wants/netavark-dhcp-proxy.socket → /usr/lib/systemd/system/netavark-dhcp-proxy.socket.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Display the socket unit file:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a macvlan network and specify your host interface with it. Typically, it is your external interface:
podman network create -d macvlan --interface-name <LAN_INTERFACE> mv1
# podman network create -d macvlan --interface-name <LAN_INTERFACE> mv1 mv1Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the container by using newly created network:
podman run --rm --network mv1 -d --name test alpine top
# podman run --rm --network mv1 -d --name test alpine top 894ae3b6b1081aca2a5d90a9855568eaa533c08a174874be59569d4656f9bc45Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Confirm the container has an IP on your local subnet:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Inspect the container to verify it uses correct IP addresses:
podman container inspect test --format {{.NetworkSettings.Networks.mv1.IPAddress}}# podman container inspect test --format {{.NetworkSettings.Networks.mv1.IPAddress}} 192.168.188.36Copy to Clipboard Copied! Toggle word wrap Toggle overflow
When attempting to connect to this IP address, ensure the connection is made from a different host. Connections from the same host are not supported when using macvlan networking.
11.3. The macvlan plugin Copy linkLink copied to clipboard!
Most of the container images do not have a DHCP client, the dhcp plugin acts as a proxy DHCP client for the containers to interact with a DHCP server.
The host system does not have network access to the container. To allow network connections from outside the host to the container, the container has to have an IP on the same network as the host. The macvlan plugin enables you to connect a container to the same network as the host.
This procedure only applies to rootfull containers. Rootless containers are not able to use the macvlan and dhcp plugins.
You can create a macvlan network by using the podman network create --driver=macvlan command.
Chapter 12. Porting containers to systemd using Podman Copy linkLink copied to clipboard!
Podman (Pod Manager) is a simple daemonless tool fully featured container engine. Podman provides a Docker-CLI comparable command line that makes the transition from other container engines easier and enables the management of pods, containers, and images.
Originally, Podman was not designed to provide an entire Linux system or manage services, such as start-up order, dependency checking, and failed service recovery. systemd was responsible for a complete system initialization. Due to Red Hat integrating containers with systemd, you can manage OCI and Docker-formatted containers built by Podman in the same way as other services and features are managed in a Linux system. You can use the systemd initialization service to work with pods and containers.
With systemd unit files, you can:
-
Set up a container or pod to start as a
systemdservice. - Define the order in which the containerized service runs and check for dependencies (for example making sure another service is running, a file is available or a resource is mounted).
-
Control the state of the
systemdsystem by using thesystemctlcommand.
You can generate portable descriptions of containers and pods by using systemd unit files.
12.1. Auto-generating a systemd unit file using Quadlets Copy linkLink copied to clipboard!
With Quadlet, you describe how to run a container in a format that is very similar to regular systemd unit files. The container descriptions focus on the relevant container details and hide technical details of running containers under systemd. Create the <CTRNAME>.container unit file in one of the following directories:
-
For root users:
/usr/share/containers/systemd/or/etc/containers/systemd/ -
For rootless users:
$HOME/.config/containers/systemd/,$XDG_CONFIG_HOME/containers/systemd/,/etc/containers/systemd/users/$(UID), or/etc/containers/systemd/users/
Quadlet is available beginning with Podman v4.6.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create the
mysleep.containerunit file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the
[Container]section you must specify:-
Image- container mage you want to tun Exec- the command you want to run inside the containerThis enables you to use all other fields specified in a
systemdunit file.
-
Create the
mysleep.servicebased on themysleep.containerfile:systemctl --user daemon-reload
$ systemctl --user daemon-reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Check the status of the
mysleep.service:systemctl --user status mysleep.service
$ systemctl --user status mysleep.service ○ mysleep.service - The sleep container Loaded: loaded (/home/username/.config/containers/systemd/mysleep.container; generated) Active: inactive (dead)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start the
mysleep.service:systemctl --user start mysleep.service
$ systemctl --user start mysleep.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Check the status of the
mysleep.service:Copy to Clipboard Copied! Toggle word wrap Toggle overflow List all containers:
podman ps -a
$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 421c8293fc1b registry.access.redhat.com/ubi10-minimal:latest sleep 1000 30 seconds ago Up 10 seconds ago systemd-mysleepCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that the name of the created container consists of the following elements:
-
a
systemd-prefix a name of the
systemdunit, that issystemd-mysleepThis naming helps to distinguish common containers from containers running in
systemdunits. It also helps to determine which unit a container runs in. If you want to change the name of the container, use theContainerNamefield in the[Container]section.For more information, see the
podman-systemd.unit(5)man page on your system.
-
a
12.2. Enabling systemd services Copy linkLink copied to clipboard!
When enabling the service, you have different options.
Procedure
Enable the service:
To enable a service at system start, no matter if user is logged in or not, enter:
systemctl enable <service>
# systemctl enable <service>Copy to Clipboard Copied! Toggle word wrap Toggle overflow You have to copy the
systemdunit files to the/etc/systemd/systemdirectory.To start a service at user login and stop it at user logout, enter:
systemctl --user enable <service>
$ systemctl --user enable <service>Copy to Clipboard Copied! Toggle word wrap Toggle overflow You have to copy the
systemdunit files to the$HOME/.config/systemd/userdirectory.To enable users to start a service at system start and persist over logouts, enter:
loginctl enable-linger <username>
# loginctl enable-linger <username>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Refer to
systemctl(1)andloginctl(1)man pages on your system for more information.
12.3. Auto-starting containers using systemd Copy linkLink copied to clipboard!
You can control the state of the systemd system and service manager by using the systemctl command. You can enable, start, stop the service as a non-root user. To install the service as a root user, omit the --user option.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Reload
systemdmanager configuration:systemctl --user daemon-reload
# systemctl --user daemon-reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enable the service
container.serviceand start it at boot time:systemctl --user enable container.service
# systemctl --user enable container.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Start the service immediately:
systemctl --user start container.service
# systemctl --user start container.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Check the status of the service:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can check if the service is enabled by using the
systemctl is-enabled container.servicecommand.
Verification
List containers that are running or have exited:
podman ps
# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f20988d59920 registry.access.redhat.com/ubi10-minimal:latest top 12 seconds ago Up 11 seconds ago funny_zhukovskyCopy to Clipboard Copied! Toggle word wrap Toggle overflow
To stop container.service, enter:
systemctl --user stop container.service
# systemctl --user stop container.service
Refer to systemctl(1) man page on your system for more information.
12.4. Advantages of using Quadlets over the podman generate systemd command Copy linkLink copied to clipboard!
You can use the Quadlets tool, which describes how to run a container in a format similar to regular systemd unit files.
Quadlet is available beginning with Podman v4.6.
Quadlets have many advantages over generating unit files by using the podman generate systemd command, such as:
-
Easy to maintain: The container descriptions focus on the relevant container details and hide technical details of running containers under
systemd. -
Automatically updated: Quadlets do not require manually regenerating unit files after an update. If a newer version of Podman is released, your service is automatically updated when the
systemclt daemon-reloadcommand is executed, for example, at boot time. - Simplified workflow: Thanks to the simplified syntax, you can create Quadlet files from scratch and deploy them anywhere.
- Support standard systemd options: Quadlet extends the existing systemd-unit syntax with new tables, for example, a table to configure a container.
Quadlet supports a subset of Kubernetes YAML capabilities. For more information, see the support matrix of supported YAML fields. You can generate the YAML files by using one of the following tools:
-
Podman:
podman generate kubecommand -
OpenShift:
oc generatecommand with the--dry-runoption -
Kubernetes:
kubectl createcommand with the--dry-runoption
Quadlet supports these unit file types:
Container units: Used to manage containers by running the
podman runcommand.-
File extension:
.container -
Section name:
[Container] -
Required fields:
Imagedescribing the container image the service runs
-
File extension:
Kube units: Used to manage containers defined in Kubernetes YAML files by running the
podman kube playcommand.-
File extension:
.kube -
Section name:
[Kube] -
Required fields:
Yamldefining the path to the Kubernetes YAML file
-
File extension:
Network units: Used to create Podman networks that may be referenced in
.containeror.kubefiles.-
File extension:
.network -
Section name:
[Network] - Required fields: None
-
File extension:
Volume units: Used to create Podman volumes that may be referenced in
.containerfiles.-
File extension:
.volume -
Section name:
[Volume] - Required fields: None
-
File extension:
For more information, see the podman-systemd.unit(5) man page on your system.
12.5. Generating a systemd unit file using Podman Copy linkLink copied to clipboard!
Podman allows systemd to control and manage container processes. You can generate a systemd unit file for the existing containers and pods by using podman generate systemd command. It is recommended to use podman generate systemd because the generated units files change frequently (via updates to Podman) and the podman generate systemd ensures that you get the latest version of unit files.
Starting with Podman v4.6, you can use the Quadlets that describe how to run a container in a format similar to regular systemd unit files and hides the complexity of running containers under systemd.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create a container (for example
myubi):podman create --name myubi registry.access.redhat.com/ubi10:latest sleep infinity
$ podman create --name myubi registry.access.redhat.com/ubi10:latest sleep infinity 0280afe98bb75a5c5e713b28de4b7c5cb49f156f1cce4a208f13fee2f75cb453Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the container name or ID to generate the
systemdunit file and direct it into the~/.config/systemd/user/container-myubi.servicefile:podman generate systemd --name myubi > ~/.config/systemd/user/container-myubi.service
$ podman generate systemd --name myubi > ~/.config/systemd/user/container-myubi.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Display the content of generated
systemdunit file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
Restart=on-failureline sets the restart policy and instructssystemdto restart when the service cannot be started or stopped cleanly, or when the process exits non-zero. -
The
ExecStartline describes how we start the container. The
ExecStopline describes how we stop and remove the container.For more information, see
podman-generate-systemd(1)man page on your system.
-
The
12.6. Automatically generating a systemd unit file using Podman Copy linkLink copied to clipboard!
By default, Podman generates a unit file for existing containers or pods. You can generate more portable systemd unit files by using the podman generate systemd --new. The --new flag instructs Podman to generate unit files that create, start and remove containers.
Starting with Podman v4.6, you can use the Quadlets that describe how to run a container in a format similar to regular systemd unit files and hides the complexity of running containers under systemd.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Pull the image you want to use on your system. For example, to pull the
httpd-24image:podman pull registry.access.redhat.com/ubi10/httpd-24
# podman pull registry.access.redhat.com/ubi10/httpd-24Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all images available on your system:
podman images
# podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.access.redhat.com/ubi10/httpd-24 latest 8594be0a0b57 2 weeks ago 462 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
httpdcontainer:podman create --name httpd -p 8080:8080 registry.access.redhat.com/ubi10/httpd-24
# podman create --name httpd -p 8080:8080 registry.access.redhat.com/ubi10/httpd-24 cdb9f981cf143021b1679599d860026b13a77187f75e46cc0eac85293710a4b1Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Verify the container has been created:
podman ps -a
# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cdb9f981cf14 registry.access.redhat.com/ubi10/httpd-24:latest /usr/bin/run-http... 5 minutes ago Created 0.0.0.0:8080->8080/tcp httpdCopy to Clipboard Copied! Toggle word wrap Toggle overflow Generate a
systemdunit file for thehttpdcontainer:podman generate systemd --new --files --name httpd
# podman generate systemd --new --files --name httpd /root/container-httpd.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Display the content of the generated
container-httpd.servicesystemdunit file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteUnit files generated by using the
--newoption do not expect containers and pods to exist. Therefore, they perform thepodman runcommand when starting the service (see theExecStartline) instead of thepodman startcommand. For example, see section Generating a systemd unit file using Podman.The
podman runcommand uses the following command-line options:-
The
--conmon-pidfileoption points to a path to store the process ID for theconmonprocess running on the host. Theconmonprocess terminates with the same exit status as the container, which allowssystemdto report the correct service status and restart the container if needed. -
The
--cidfileoption points to the path that stores the container ID. -
The
%tis the path to the run time directory root, for example/run/user/$UserID. -
The
%nis the full name of the service.
-
The
Copy unit files to
/etc/systemd/systemfor installing them as a root user:cp -Z container-httpd.service /etc/systemd/system
# cp -Z container-httpd.service /etc/systemd/systemCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enable and start the
container-httpd.service:systemctl daemon-reload systemctl enable --now container-httpd.service
# systemctl daemon-reload # systemctl enable --now container-httpd.service Created symlink /etc/systemd/system/multi-user.target.wants/container-httpd.service → /etc/systemd/system/container-httpd.service. Created symlink /etc/systemd/system/default.target.wants/container-httpd.service → /etc/systemd/system/container-httpd.service.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Check the status of the
container-httpd.service:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.7. Automatically starting pods using systemd Copy linkLink copied to clipboard!
You can start multiple containers as systemd services. Note that the systemctl command should only be used on the pod and you should not start or stop containers individually via systemctl, as they are managed by the pod service along with the internal infra-container.
Starting with Podman v4.6, you can use the Quadlets that describe how to run a container in a format similar to regular systemd unit files and hides the complexity of running containers under systemd.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create an empty pod, for example named
systemd-pod:podman pod create --name systemd-pod
$ podman pod create --name systemd-pod 11d4646ba41b1fffa51c108cbdf97cfab3213f7bd9b3e1ca52fe81b90fed5577Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all pods:
podman pod ps
$ podman pod ps POD ID NAME STATUS CREATED # OF CONTAINERS INFRA ID 11d4646ba41b systemd-pod Created 40 seconds ago 1 8a428b257111 11d4646ba41b1fffa51c108cbdf97cfab3213f7bd9b3e1ca52fe81b90fed5577Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create two containers in the empty pod. For example, to create
container0andcontainer1insystemd-pod:*podman create --pod systemd-pod --name container0 registry.access.redhat.com/ubi*10 top *podman create --pod systemd-pod --name container1 registry.access.redhat.com/ubi*10 top
$ *podman create --pod systemd-pod --name container0 registry.access.redhat.com/ubi*10 top $ *podman create --pod systemd-pod --name container1 registry.access.redhat.com/ubi*10 topCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all pods and containers associated with them:
podman ps -a --pod
$ podman ps -a --pod CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD ID PODNAME 24666f47d9b2 registry.access.redhat.com/ubi10:latest top 3 minutes ago Created container0 3130f724e229 systemd-pod 56eb1bf0cdfe k8s.gcr.io/pause:3.2 4 minutes ago Created 3130f724e229-infra 3130f724e229 systemd-pod 62118d170e43 registry.access.redhat.com/ubi10:latest top 3 seconds ago Created container1 3130f724e229 systemd-podCopy to Clipboard Copied! Toggle word wrap Toggle overflow Generate the
systemdunit file for the new pod:podman generate systemd --files --name systemd-pod
$ podman generate systemd --files --name systemd-pod /home/user1/pod-systemd-pod.service /home/user1/container-container0.service /home/user1/container-container1.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that three
systemdunit files are generated, one for thesystemd-podpod and two for the containerscontainer0andcontainer1.Display
pod-systemd-pod.serviceunit file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
Requiresline in the[Unit]section defines dependencies oncontainer-container0.serviceandcontainer-container1.serviceunit files. Both unit files will be activated. -
The
ExecStartandExecStoplines in the[Service]section start and stop the infra-container, respectively.
-
The
Display
container-container0.serviceunit file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
BindsToline line in the[Unit]section defines the dependency on thepod-systemd-pod.serviceunit file -
The
ExecStartandExecStoplines in the[Service]section start and stop thecontainer0respectively.
-
The
Display
container-container1.serviceunit file:cat container-container1.service
$ cat container-container1.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy all the generated files to
$HOME/.config/systemd/userfor installing as a non-root user:cp pod-systemd-pod.service container-container0.service container-container1.service $HOME/.config/systemd/user
$ cp pod-systemd-pod.service container-container0.service container-container1.service $HOME/.config/systemd/userCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enable the service and start at user login:
systemctl enable --user pod-systemd-pod.service
$ systemctl enable --user pod-systemd-pod.service Created symlink /home/user1/.config/systemd/user/multi-user.target.wants/pod-systemd-pod.service → /home/user1/.config/systemd/user/pod-systemd-pod.service. Created symlink /home/user1/.config/systemd/user/default.target.wants/pod-systemd-pod.service → /home/user1/.config/systemd/user/pod-systemd-pod.service.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note that the service stops at user logout.
Verification
Check if the service is enabled:
systemctl is-enabled pod-systemd-pod.service
$ systemctl is-enabled pod-systemd-pod.service enabledCopy to Clipboard Copied! Toggle word wrap Toggle overflow
For more information, see the podman-create(1), podman-generate-systemd(1), and systemctl(1) man pages on your system.
12.8. Automatically updating containers using Podman Copy linkLink copied to clipboard!
The podman auto-update command allows you to automatically update containers according to their auto-update policy. The podman auto-update command updates services when the container image is updated on the registry. To use auto-updates, containers must be created with the --label "io.containers.autoupdate=image" label and run in a systemd unit generated by podman generate systemd --new command.
Podman searches for running containers with the "io.containers.autoupdate" label set to "image" and communicates to the container registry. If the image has changed, Podman restarts the corresponding systemd unit to stop the old container and create a new one with the new image. As a result, the container, its environment, and all dependencies, are restarted.
Starting with Podman v4.6, you can use the Quadlets that describe how to run a container in a format similar to regular systemd unit files and hides the complexity of running containers under systemd.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Start a
myubicontainer based on theregistry.access.redhat.com/ubi10/ubi-initimage:podman run --label "io.containers.autoupdate=image" \ --name myubi -dt registry.access.redhat.com/ubi10/ubi-init top
# podman run --label "io.containers.autoupdate=image" \ --name myubi -dt registry.access.redhat.com/ubi10/ubi-init top bc219740a210455fa27deacc96d50a9e20516492f1417507c13ce1533dbdcd9dCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List containers that are running or have exited:
podman ps -a
# podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 76465a5e2933 registry.access.redhat.com/10/ubi-init:latest top 24 seconds ago Up 23 seconds ago myubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow Generate a
systemdunit file for themyubicontainer:podman generate systemd --new --files --name myubi
# podman generate systemd --new --files --name myubi /root/container-myubi.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy unit files to
/usr/lib/systemd/systemfor installing it as a root user:cp -Z ~/container-myubi.service /usr/lib/systemd/system
# cp -Z ~/container-myubi.service /usr/lib/systemd/systemCopy to Clipboard Copied! Toggle word wrap Toggle overflow Reload
systemdmanager configuration:systemctl daemon-reload
# systemctl daemon-reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow Start and check the status of a container:
systemctl start container-myubi.service systemctl status container-myubi.service
# systemctl start container-myubi.service # systemctl status container-myubi.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow Auto-update the container:
podman auto-update
# podman auto-updateCopy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-generate-systemd(1), andsystemctl(1)man pages on your system.
12.9. Automatically updating containers using systemd Copy linkLink copied to clipboard!
As mentioned in section Automatically updating containers using Podman, you can update the container by using the podman auto-update command. It integrates into custom scripts and can be invoked when needed. Another way to auto update the containers is to use the pre-installed podman-auto-update.timer and podman-auto-update.service systemd service. The podman-auto-update.timer can be configured to trigger auto updates at a specific date or time. The podman-auto-update.service can further be started by the systemctl command or be used as a dependency by other systemd services. As a result, auto updates based on time and events can be triggered in various ways to meet individual needs and use cases.
Starting with Podman v4.6, you can use the Quadlets that describe how to run a container in a format similar to regular systemd unit files and hides the complexity of running containers under systemd.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Display the
podman-auto-update.serviceunit file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display the
podman-auto-update.timerunit file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example, the
podman auto-updatecommand is launched daily at midnight.Enable the
podman-auto-update.timerservice at system start:systemctl enable podman-auto-update.timer
# systemctl enable podman-auto-update.timerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Start the
systemdservice:systemctl start podman-auto-update.timer
# systemctl start podman-auto-update.timerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all timers:
systemctl list-timers --all
# systemctl list-timers --all NEXT LEFT LAST PASSED UNIT ACTIVATES Wed 2020-12-09 00:00:00 CET 9h left n/a n/a podman-auto-update.timer podman-auto-update.serviceCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can see that
podman-auto-update.timeractivates thepodman-auto-update.service.
Chapter 13. Porting containers to OpenShift using Podman Copy linkLink copied to clipboard!
You can generate portable descriptions of containers and pods by using the YAML ("YAML Ain’t Markup Language") format. The YAML is a text format used to describe the configuration data.
The YAML files are:
- Readable.
- Easy to generate.
- Portable between environments (for example between RHEL and OpenShift).
- Portable between programming languages.
- Convenient to use (no need to add all the parameters to the command line).
Reasons to use YAML files:
- You can re-run a local orchestrated set of containers and pods with minimal input required which can be useful for iterative development.
-
You can run the same containers and pods on another machine. For example, to run an application in an OpenShift environment and to ensure that the application is working correctly. You can use
podman generate kubecommand to generate a Kubernetes YAML file. Then, you can usepodman playcommand to test the creation of pods and containers on your local system before you transfer the generated YAML files to the Kubernetes or OpenShift environment. Withpodman playcommand, you can also recreate pods and containers originally created in OpenShift or Kubernetes environments.
The podman kube play command supports a subset of Kubernetes YAML capabilities. For more information, see the support matrix of supported YAML fields.
13.1. Generating a Kubernetes YAML file using Podman Copy linkLink copied to clipboard!
You can create a pod with one container and generate the Kubernetes YAML file by using the podman generate kube command.
Prerequisites
-
The
container-toolsmeta-package is installed. - The pod has been created. For details, see section Creating pods.
Procedure
List all pods and containers associated with them:
podman ps -a --pod
$ podman ps -a --pod CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD 5df5c48fea87 registry.access.redhat.com/ubi10/ubi:latest /bin/bash Less than a second ago Up Less than a second ago myubi 223df6b390b4 3afdcd93de3e k8s.gcr.io/pause:3.1 Less than a second ago Up Less than a second ago 223df6b390b4-infra 223df6b390b4Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the pod name or ID to generate the Kubernetes YAML file:
podman generate kube mypod > mypod.yaml
$ podman generate kube mypod > mypod.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that the
podman generatecommand does not reflect any Logical Volume Manager (LVM) logical volumes or physical volumes that might be attached to the container.Display the
mypod.yamlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
13.2. Generating a Kubernetes YAML file in OpenShift environment Copy linkLink copied to clipboard!
In the OpenShift environment, use the oc create command to generate the YAML files describing your application.
Procedure
Generate the YAML file for your
myappapplication:oc create myapp --image=me/myapp:v1 -o yaml --dry-run > myapp.yaml
$ oc create myapp --image=me/myapp:v1 -o yaml --dry-run > myapp.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
oc createcommand creates and run themyappimage. The object is printed using the--dry-runoption and redirected into themyapp.yamloutput file.
In the Kubernetes environment, you can use the kubectl create command with the same flags.
13.3. Starting containers and pods with Podman Copy linkLink copied to clipboard!
With the generated YAML files, you can automatically start containers and pods in any environment. The YAML files can be generated by using tools other than Podman, such as Kubernetes or Openshift. The podman play kube command allows you to recreate pods and containers based on the YAML input file.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create the pod and the container from the
mypod.yamlfile:podman play kube mypod.yaml
$ podman play kube mypod.yaml Pod: b8c5b99ba846ccff76c3ef257e5761c2d8a5ca4d7ffa3880531aec79c0dacb22 Container: 848179395ebd33dd91d14ffbde7ae273158d9695a081468f487af4e356888eceCopy to Clipboard Copied! Toggle word wrap Toggle overflow List all pods:
podman pod ps
$ podman pod ps POD ID NAME STATUS CREATED # OF CONTAINERS INFRA ID b8c5b99ba846 mypod Running 19 seconds ago 2 aa4220eaf4bbCopy to Clipboard Copied! Toggle word wrap Toggle overflow List all pods and containers associated with them:
podman ps -a --pod
$ podman ps -a --pod CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD 848179395ebd registry.access.redhat.com/ubi10/ubi:latest /bin/bash About a minute ago Up About a minute ago myubi b8c5b99ba846 aa4220eaf4bb k8s.gcr.io/pause:3.1 About a minute ago Up About a minute ago b8c5b99ba846-infra b8c5b99ba846Copy to Clipboard Copied! Toggle word wrap Toggle overflow The pod IDs from
podman pscommand matches the pod ID from thepodman pod pscommand.For more information, see the
podman-play-kube(1)man page on your system.
13.4. Starting containers and pods in OpenShift environment Copy linkLink copied to clipboard!
You can use the oc create command to create pods and containers in the OpenShift environment.
Procedure
Create a pod from the YAML file in the OpenShift environment:
oc create -f mypod.yaml
$ oc create -f mypod.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIn the Kubernetes environment, you can use the
kubectl createcommand with the same flags.
13.5. Manually running containers and pods using Podman Copy linkLink copied to clipboard!
The following procedure shows how to manually create a WordPress content management system paired with a MariaDB database by using Podman.
Suppose the following directory layout:
├── mariadb-conf │ ├── Containerfile │ ├── my.cnf
├── mariadb-conf
│ ├── Containerfile
│ ├── my.cnf
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Display the
mariadb-conf/Containerfilefile:cat mariadb-conf/Containerfile FROM docker.io/library/mariadb COPY my.cnf /etc/mysql/my.cnf
$ cat mariadb-conf/Containerfile FROM docker.io/library/mariadb COPY my.cnf /etc/mysql/my.cnfCopy to Clipboard Copied! Toggle word wrap Toggle overflow Display the
mariadb-conf/my.cnffile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build the
docker.io/library/mariadbimage by usingmariadb-conf/Containerfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all images:
podman images
$ podman images LIST IMAGES REPOSITORY TAG IMAGE ID CREATED SIZE localhost/mariadb-conf latest b66fa0fa0ef2 57 seconds ago 416 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the pod named
wordpresspodand configure port mappings between the container and the host system:podman pod create --name wordpresspod -p 8080:80
$ podman pod create --name wordpresspod -p 8080:80Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
mydbcontainer inside thewordpresspodpod:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
mywebcontainer inside thewordpresspodpod:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all pods and containers associated with them:
podman ps --pod -a
$ podman ps --pod -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD ID PODNAME 9ea56f771915 k8s.gcr.io/pause:3.5 Less than a second ago Up Less than a second ago 0.0.0.0:8080->80/tcp 4b7f054a6f01-infra 4b7f054a6f01 wordpresspod 60e8dbbabac5 localhost/mariadb-conf:latest mariadbd Less than a second ago Up Less than a second ago 0.0.0.0:8080->80/tcp mydb 4b7f054a6f01 wordpresspod 045d3d506e50 docker.io/library/wordpress:latest apache2-foregroun... Less than a second ago Up Less than a second ago 0.0.0.0:8080->80/tcp myweb 4b7f054a6f01 wordpresspodCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that the pod is running: Visit the http://localhost:8080/wp-admin/install.php page or use the
curlcommand:Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-play-kube(1)man page on your system.
13.6. Generating a YAML file using Podman Copy linkLink copied to clipboard!
You can generate a Kubernetes YAML file by using the podman generate kube command.
Prerequisites
-
The
container-toolsmeta-package is installed. -
The pod named
wordpresspodhas been created. For details, see section Creating pods.
Procedure
List all pods and containers associated with them:
podman ps --pod -a
$ podman ps --pod -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD ID PODNAME 9ea56f771915 k8s.gcr.io/pause:3.5 Less than a second ago Up Less than a second ago 0.0.0.0:8080->80/tcp 4b7f054a6f01-infra 4b7f054a6f01 wordpresspod 60e8dbbabac5 localhost/mariadb-conf:latest mariadbd Less than a second ago Up Less than a second ago 0.0.0.0:8080->80/tcp mydb 4b7f054a6f01 wordpresspod 045d3d506e50 docker.io/library/wordpress:latest apache2-foregroun... Less than a second ago Up Less than a second ago 0.0.0.0:8080->80/tcp myweb 4b7f054a6f01 wordpresspodCopy to Clipboard Copied! Toggle word wrap Toggle overflow Use the pod name or ID to generate the Kubernetes YAML file:
podman generate kube wordpresspod >> wordpresspod.yaml
$ podman generate kube wordpresspod >> wordpresspod.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Display the
wordpresspod.yamlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-play-kube(1)man page on your system.
13.7. Automatically running containers and pods using Podman Copy linkLink copied to clipboard!
You can use the podman play kube command to test the creation of pods and containers on your local system before you transfer the generated YAML files to the Kubernetes or OpenShift environment.
The podman play kube command can also automatically build and run multiple pods with multiple containers in the pod by using the YAML file similarly to the docker compose command. The images are automatically built if the following conditions are met:
- a directory with the same name as the image used in YAML file exists
- that directory contains a Containerfile
Prerequisites
-
The
container-toolsmeta-package is installed. -
The pod named
wordpresspodhas been created. For details, see section Manually running containers and pods using Podman. - The YAML file has been generated. For details, see section Generating a YAML file using Podman.
To repeat the whole scenario from the beginning, delete locally stored images:
podman rmi localhost/mariadb-conf podman rmi docker.io/library/wordpress podman rmi docker.io/library/mysql
$ podman rmi localhost/mariadb-conf $ podman rmi docker.io/library/wordpress $ podman rmi docker.io/library/mysqlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Create the wordpress pod by using the
wordpress.yamlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
podman play kubecommand:-
Automatically build the
localhost/mariadb-conf:latestimage based ondocker.io/library/mariadbimage. -
Pull the
docker.io/library/wordpress:latestimage. -
Create a pod named
wordpresspodwith two containers namedwordpresspod-mydbandwordpresspod-myweb.
-
Automatically build the
List all containers and pods:
podman ps --pod -a
$ podman ps --pod -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD ID PODNAME a1dbf7b5606c k8s.gcr.io/pause:3.5 3 minutes ago Up 2 minutes ago 0.0.0.0:8080->80/tcp 3e391d091d19-infra 3e391d091d19 wordpresspod 6c59ebe96846 localhost/mariadb-conf:latest mariadbd 2 minutes ago Exited (1) 2 minutes ago 0.0.0.0:8080->80/tcp wordpresspod-mydb 3e391d091d19 wordpresspod 29717878452f docker.io/library/wordpress:latest apache2-foregroun... 2 minutes ago Up 2 minutes ago 0.0.0.0:8080->80/tcp wordpresspod-myweb 3e391d091d19 wordpresspodCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that the pod is running: Visit the http://localhost:8080/wp-admin/install.php page or use the
curlcommand:Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-play-kube(1)man page on your system.
13.8. Automatically stopping and removing pods using Podman Copy linkLink copied to clipboard!
The podman play kube --down command stops and removes all pods and their containers.
If a volume is in use, it is not removed.
Prerequisites
-
The
container-toolsmeta-package is installed. -
The pod named
wordpresspodhas been created. For details, see section Manually running containers and pods using Podman. - The YAML file has been generated. For details, see section Generating a YAML file using Podman.
- The pod is running. For details, see section Automatically running containers and pods using Podman.
Procedure
Remove all pods and containers created by the
wordpresspod.yamlfile:podman play kube --down wordpresspod.yaml
$ podman play kube --down wordpresspod.yaml Pods stopped: 3e391d091d190756e655219a34de55583eed3ef59470aadd214c1fc48cae92ac Pods removed: 3e391d091d190756e655219a34de55583eed3ef59470aadd214c1fc48cae92acCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that all pods and containers created by the
wordpresspod.yamlfile were removed:podman ps --pod -a
$ podman ps --pod -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES POD ID PODNAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow Refer to
podman-play-kube(1)man page on your system for more information.
Chapter 14. Managing containers by using RHEL system roles Copy linkLink copied to clipboard!
With the podman RHEL system role, you can manage Podman configuration, containers, and systemd services that run Podman containers.
14.1. Configuring image registry management for Podman and other container tools Copy linkLink copied to clipboard!
With podman RHEL system role, you can automate Podman management, including registry configuration, across multiple RHEL systems. Instead of manually editing files, you define your desired registry configuration in an Ansible playbook. The podman RHEL system role uses the podman_registries_conf variable, which accepts a dictionary containing the registry settings. The role then creates a drop-in file, for example, in the /etc/containers/registries.conf.d/ to apply your configuration, following best practices for managing system configurations.
Prerequisites
- You have prepared the control node and the managed nodes.
- You are logged in to the control node as a user who can run playbooks on the managed nodes.
-
The account you use to connect to the managed nodes has
sudopermissions on them.
Procedure
Create a playbook file, for example,
~/playbook.yml, with the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The settings specified in the example playbook include the following:
-
unqualified-search-registries: Extends the list of registries Podman searches when you use a short image name (for example,podman pull <my-image>). Podman searches for images in my-company-registry.com after the default registries. -
[registry]: Defines specific properties for a given registry. For example, you can enable an insecure connection by settinginsecure=trueto a local registry running at my-local-registry:5000.
The
podman_use_new_toml_formattervariable generates TOML-compliant configuration files that are compatible with Podman. This variable enhances the Podman role by supporting all TOML features, including tables and inline tables, through a true TOML formatter instead of the Jinja template used previously.The new formatter is disabled by default to maintain compatibility with the previous formatter’s behavior. To enable the new formatter, set
podman_use_new_toml_formatter: truein your configuration:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Validate the playbook syntax:
ansible-playbook --syntax-check ~/playbook.yml
$ ansible-playbook --syntax-check ~/playbook.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that this command only validates the syntax and does not protect against a wrong but valid configuration.
Run the playbook:
ansible-playbook ~/playbook.yml
$ ansible-playbook ~/playbook.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
14.2. Creating a rootless container with bind mount by using the podman RHEL system role Copy linkLink copied to clipboard!
You can use the podman RHEL system role to create rootless containers with bind mount by running an Ansible playbook and with that, manage your application configuration.
The example Ansible playbook starts two Kubernetes pods: one for a database and another for a web application. The database pod configuration is specified in the playbook, while the web application pod is defined in an external YAML file.
Prerequisites
- You have prepared the control node and the managed nodes.
- You are logged in to the control node as a user who can run playbooks on the managed nodes.
-
The account you use to connect to the managed nodes has
sudopermissions on them. -
The user and group
webappexist, and must be listed in the/etc/subuidand/etc/subgidfiles on the host. -
The user named
dbuserand a group nameddbgroupmust be already created.
Procedure
Create a playbook file, for example,
~/playbook.yml, with the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The settings specified in the example playbook include the following:
run_as_userandrun_as_group- Specify that containers are rootless.
kube_file_contentContains a Kubernetes YAML file defining the first container named
db. You can generate the Kubernetes YAML file by using thepodman kube generatecommand.-
The
dbcontainer is based on thequay.io/db/db:stablecontainer image. -
The
dbbind mount maps the/var/lib/dbdirectory on the host to the/var/lib/dbdirectory in the container. TheZflag labels the content with a private unshared label, therefore, only thedbcontainer can access the content.
-
The
kube_file_src: <path>-
Defines the second container. The content of the
/path/to/webapp.ymlfile on the controller node will be copied to thekube_filefield on the managed node. volumes: <list>-
A YAML list to define the source of the data to provide in one or more containers. For example, a local disk on the host (
hostPath) or other disk device. volumeMounts: <list>- A YAML list to define the destination where the individual container will mount a given volume.
podman_create_host_directories: true-
Creates the directory on the host. This instructs the role to check the kube specification for
hostPathvolumes and create those directories on the host. If you need more control over the ownership and permissions, usepodman_host_directories.
For details about all variables used in the playbook, see the
/usr/share/ansible/roles/rhel-system-roles.podman/README.mdfile on the control node.Validate the playbook syntax:
ansible-playbook --syntax-check --ask-vault-pass ~/playbook.yml
$ ansible-playbook --syntax-check --ask-vault-pass ~/playbook.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that this command only validates the syntax and does not protect against a wrong but valid configuration.
Run the playbook:
ansible-playbook --ask-vault-pass ~/playbook.yml
$ ansible-playbook --ask-vault-pass ~/playbook.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
14.3. Creating a rootful container with Podman volume by using the podman RHEL system role Copy linkLink copied to clipboard!
You can use the podman RHEL system role to create a rootful container with a Podman volume by running an Ansible playbook and with that, manage your application configuration.
The example Ansible playbook deploys a Kubernetes pod named ubi8-httpd running an HTTP server container from the registry.access.redhat.com/ubi8/httpd-24 image. The container’s web content is mounted from a persistent volume named ubi8-html-volume. By default, the podman role creates rootful containers.
Prerequisites
- You have prepared the control node and the managed nodes.
- You are logged in to the control node as a user who can run playbooks on the managed nodes.
-
The account you use to connect to the managed nodes has
sudopermissions on them.
Procedure
Create a playbook file, for example,
~/playbook.yml, with the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The settings specified in the example playbook include the following:
kube_file_contentContains a Kubernetes YAML file defining the first container named
db. You can generate the Kubernetes YAML file by using thepodman kube generatecommand.-
The
ubi8-httpdcontainer is based on theregistry.access.redhat.com/ubi8/httpd-24container image. -
The
ubi8-html-volumemaps the/var/www/htmldirectory on the host to the container. TheZflag labels the content with a private unshared label, therefore, only theubi8-httpdcontainer can access the content. -
The pod mounts the existing persistent volume named
ubi8-html-volumewith the mount path/var/www/html.
-
The
For details about all variables used in the playbook, see the
/usr/share/ansible/roles/rhel-system-roles.podman/README.mdfile on the control node.Validate the playbook syntax:
ansible-playbook --syntax-check ~/playbook.yml
$ ansible-playbook --syntax-check ~/playbook.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that this command only validates the syntax and does not protect against a wrong but valid configuration.
Run the playbook:
ansible-playbook ~/playbook.yml
$ ansible-playbook ~/playbook.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
14.4. Creating a Quadlet application with secrets by using the podman RHEL system role Copy linkLink copied to clipboard!
You can use the podman RHEL system role to create a Quadlet application with secrets by running an Ansible playbook.
Prerequisites
- You have prepared the control node and the managed nodes.
- You are logged in to the control node as a user who can run playbooks on the managed nodes.
-
The account you use to connect to the managed nodes has
sudopermissions on them. -
The certificate and the corresponding private key that the web server in the container should use are stored in the
~/certificate.pemand~/key.pemfiles.
Procedure
Display the contents of the certificate and private key files:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You require this information in a later step.
Store your sensitive variables in an encrypted file:
Create the vault:
ansible-vault create ~/vault.yml
$ ansible-vault create ~/vault.yml New Vault password: <vault_password> Confirm New Vault password: <vault_password>Copy to Clipboard Copied! Toggle word wrap Toggle overflow After the
ansible-vault createcommand opens an editor, enter the sensitive data in the<key>: <value>format:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Ensure that all lines in the
certificateandkeyvariables start with two spaces.- Save the changes, and close the editor. Ansible encrypts the data in the vault.
Create a playbook file, for example,
~/playbook.yml, with the following content:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The procedure creates a WordPress content management system paired with a MySQL database. The
podman_quadlet_specs rolevariable defines a set of configurations for the Quadlet, which refers to a group of containers or services that work together in a certain way. It includes the following specifications:-
The Wordpress network is defined by the
quadlet-demonetwork unit. -
The volume configuration for MySQL container is defined by the
file_src: quadlet-demo-mysql.volumefield. -
The
template_src: quadlet-demo-mysql.container.j2field is used to generate a configuration for the MySQL container. -
Two YAML files follow:
file_src: envoy-proxy-configmap.ymlandfile_src: quadlet-demo.yml. Note that .yml is not a valid Quadlet unit type, therefore these files will just be copied and not processed as a Quadlet specification. The Wordpress and envoy proxy containers and configuration are defined by the
file_src: quadlet-demo.kubefield. The kube unit refers to the previous YAML files in the[Kube]section asYaml=quadlet-demo.ymlandConfigMap=envoy-proxy-configmap.yml.For details about all variables used in the playbook, see the
/usr/share/ansible/roles/rhel-system-roles.podman/README.mdfile on the control node.
-
The Wordpress network is defined by the
Validate the playbook syntax:
ansible-playbook --syntax-check --ask-vault-pass ~/playbook.yml
$ ansible-playbook --syntax-check --ask-vault-pass ~/playbook.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Note that this command only validates the syntax and does not protect against a wrong but valid configuration.
Run the playbook:
ansible-playbook --ask-vault-pass ~/playbook.yml
$ ansible-playbook --ask-vault-pass ~/playbook.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Chapter 15. Managing container images by using the RHEL web console Copy linkLink copied to clipboard!
You can use the RHEL web console web-based interface to pull, prune, or delete your container images.
15.1. Pulling container images in the web console Copy linkLink copied to clipboard!
You can download container images to your local system and use them to create your containers.
Prerequisites
You have installed the RHEL 10 web console.
For instructions, see Installing and enabling the web console.
The
cockpit-podmanadd-on is installed:dnf install cockpit-podman
# dnf install cockpit-podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
- Log in to the RHEL 10 web console.
- Click Podman containers in the main menu.
- In the Images table, click the overflow menu in the upper-right corner and select Download new image.
- The Search for an image dialog box appears.
- In the Search for field, enter the name of the image or specify its description.
- In the in drop-down list, select the registry from which you want to pull the image.
- Optional: In the Tag field, enter the tag of the image.
- Click .
Verification
- Click Podman containers in the main menu. You can see the newly downloaded image in the Images table.
You can create a container from the downloaded image by clicking the button in the Images table. To create the container, follow steps 3-8 in Creating containers in the web console.
15.2. Pruning container images in the web console Copy linkLink copied to clipboard!
You can remove all unused images that do not have any containers based on it.
Prerequisites
- At least one container image is pulled.
- You have installed the RHEL 10 web console. For instructions, see Installing and enabling the web console.
The
cockpit-podmanadd-on is installed:dnf install cockpit-podman
# dnf install cockpit-podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
- Log in to the RHEL 10 web console.
- Click Podman containers in the main menu.
- In the Images table, click the overflow menu in the upper-right corner and select Prune unused images.
- The pop-up window with the list of images appears. Click Prune to confirm your choice.
Verification
- Click Podman containers in the main menu. The deleted images should not be listed in the Images table.
15.3. Deleting container images in the web console Copy linkLink copied to clipboard!
You can delete a previously pulled container image by using the web console.
Prerequisites
- At least one container image is pulled.
- You have installed the RHEL 10 web console.
The
cockpit-podmanadd-on is installed:dnf install cockpit-podman
# dnf install cockpit-podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
- Log in to the RHEL 10 web console.
-
Click
Podman containersbutton in the main menu. - In the Images table, select the image you want to delete and click the overflow menu and select Delete.
- The window appears. Click Delete tagged images to confirm your choice.
Verification
- Click the Podman containers in the main menu. The deleted container should not be listed in the Images table.
Chapter 16. Managing containers by using the RHEL web console Copy linkLink copied to clipboard!
You can use the RHEL web console to manage your containers and pods. With the web console, you can create containers as a non-root or root user.
- As a root user, you can create system containers with extra privileges and options.
As a non-root user, you have two options:
- To only create user containers, you can use the web console in its default mode - Limited access.
- To create both user and system containers, click Administrative access in the top panel of the web console page.
For details about differences between root and rootless containers, see Special considerations for rootless containers.
16.1. Creating a container checkpoint in the web console Copy linkLink copied to clipboard!
With the web console, you can set a checkpoint on a running container or an individual application and store its state to disk.
Creating a checkpoint is available only for system containers.
Prerequisites
- The container is running.
You have installed the RHEL 10 web console.
For instructions, see Installing and enabling the web console.
The
cockpit-podmanadd-on is installed:dnf install cockpit-podman
# dnf install cockpit-podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
- Log in to the RHEL 10 web console.
- Click Podman containers in the main menu.
- In the Containers table, select the container you want to modify and click the overflow icon menu and select Checkpoint.
Optional: In the Checkpoint container form, check the options you need:
- Keep all temporary checkpoint files: keep all temporary log and statistics files created by CRIU during checkpointing. These files are not deleted if checkpointing fails for further debugging.
- Leave running after writing checkpoint to disk: leave the container running after checkpointing instead of stopping it.
- Support preserving established TCP connections
- Click .
Verification
- Click the Podman containers in the main menu. Select the container you checkpointed, click the overflow menu icon and verify that there is a Restore option.
16.2. Restoring a container checkpoint in the web console Copy linkLink copied to clipboard!
You can use data saved to restore the container after a reboot at the same point in time it was checkpointed.
Creating a checkpoint is available only for system containers.
Prerequisites
- The container was checkpointed.
- You have installed the RHEL 10 web console. For instructions, see Installing and enabling the web console.
The
cockpit-podmanadd-on is installed:dnf install cockpit-podman
# dnf install cockpit-podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
- Log in to the RHEL 10 web console.
- Click Podman containers in the main menu.
- In the Containers table, select the container you want to modify and click the overflow menu and select Restore.
Optional: In the Restore container form, check the options you need:
- Keep all temporary checkpoint files: Keep all temporary log and statistics files created by CRIU during checkpointing. These files are not deleted if checkpointing fails for further debugging.
- Restore with established TCP connections
- Ignore IP address if set statically: If the container was started with IP address the restored container also tries to use that IP address and restore fails if that IP address is already in use. This option is applicable if you added port mapping in the Integration tab when you create the container.
- Ignore MAC address if set statically: If the container was started with MAC address the restored container also tries to use that MAC address and restore fails if that MAC address is already in use.
- Click .
Verification
- Click the Podman containers in the main menu. You can see that the restored container in the Containers table is running.
16.3. Creating pods in the web console Copy linkLink copied to clipboard!
You can create pods in the RHEL web console interface.
Prerequisites
You have installed the RHEL 10 web console.
For instructions, see Installing and enabling the web console.
The
cockpit-podmanadd-on is installed:dnf install cockpit-podman
# dnf install cockpit-podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
- Log in to the RHEL 10 web console.
- Click Podman containers in the main menu.
- Click .
Provide desired information in the Create pod form:
- Available only with the administrative access: Select the Owner of the container: System or User.
- In the Name field, enter the name of your container.
Click to add port mapping between container and host system.
- Enter the IP address, Host port, Container port and Protocol.
Click to add volume.
- Enter the host path, Container path. You can check the Writable checkbox to create a writable volume. In the SELinux drop down list, select one of the following options: No Label, Shared or Private.
- Click .
Verification
- Click Podman containers in the main menu. You can see the newly created pod in the Containers table.
16.4. Creating containers in the pod in the web console Copy linkLink copied to clipboard!
You can create a container in a pod.
Prerequisites
You have installed the RHEL 10 web console.
For instructions, see Installing and enabling the web console.
The
cockpit-podmanadd-on is installed:dnf install cockpit-podman
# dnf install cockpit-podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
- Log in to the RHEL 10 web console.
- Click Podman containers in the main menu.
- Click .
- In the Name field, enter the name of your container.
Provide the required information in the Details tab.
- Available only with the administrative access: Select the Owner of the container: System or User.
In the Image drop down list select or search the container image in selected registries.
- Optional: Check the Pull latest image checkbox to pull the latest container image.
The Command field specifies the command. You can change the default command if you need.
- Optional: Check the With terminal checkbox to run your container with a terminal.
- The Memory limit field specifies the memory limit for the container. To change the default memory limit, check the checkbox and specify the limit.
- Available only for system containers: In the CPU shares field, specify the relative amount of CPU time. Default value is 1024. Check the checkbox to modify the default value.
Available only for system containers: In the Restart policy drop down menu, select one of the following options:
- No (default value): No action.
- On Failure: Restarts a container on failure.
- Always: Restarts container when exits or after system boot.
Provide the required information in the Integration tab.
Click to add port mapping between the container and host system.
- Enter the IP address, Host port, Container port and Protocol.
Click to add volume.
- Enter the host path, Container path. You can check the Writable option checkbox to create a writable volume. In the SELinux drop down list, select one of the following options: No Label, Shared, or Private.
Click to add environment variable.
- Enter the Key and Value.
Provide the required information in the Health check tab.
- In the Command fields, enter the healthcheck command.
Specify the healthcheck options:
- Interval (default is 30 seconds)
- Timeout (default is 30 seconds)
- Start period
- Retries (default is 3)
When unhealthy: Select one of the following options:
- No action (default): Take no action.
- Restart: Restart the container.
- Stop: Stop the container.
Force stop: Force stops the container, it does not wait for the container to exit.
NoteThe owner of the container and pod are same. In the pod, you can inspect containers, change the status of containers, commit containers, or delete containers.
Verification
- Click Podman containers in the main menu. You can see the newly created container in the pod under the Containers table.
Chapter 17. Running Skopeo, Buildah, and Podman in a container Copy linkLink copied to clipboard!
You can run Skopeo, Buildah, and Podman in a container.
With Skopeo, you can inspect images on a remote registry without having to download the entire image with all its layers. You can also use Skopeo for copying images, signing images, syncing images, and converting images across different formats and layer compressions.
Buildah facilitates building OCI container images. With Buildah, you can create a working container, either from scratch or using an image as a starting point. You can create an image either from a working container or using the instructions in a Containerfile. You can mount and unmount a working container’s root filesystem.
With Podman, you can manage containers and images, volumes mounted into those containers, and pods made from groups of containers. Podman is based on a libpod library for container lifecycle management. The libpod library provides APIs for managing containers, pods, container images, and volumes.
Reasons to run Buildah, Skopeo, and Podman in a container:
CI/CD system:
- Podman and Skopeo: You can run a CI/CD system inside of Kubernetes or use OpenShift to build your container images, and possibly distribute those images across different container registries. To integrate Skopeo into a Kubernetes workflow, you need to run it in a container.
-
Buildah: You want to build OCI/container images within a Kubernetes or OpenShift CI/CD systems that are constantly building images. Previously, people used a Docker socket to connect to the container engine and perform a
docker buildcommand. This was the equivalent of giving root access to the system without requiring a password which is not secure. For this reason, Red Hat recommends using Buildah in a container.
Different versions:
- All: You are running an older operating system on the host but you want to run the latest version of Skopeo, Buildah, or Podman. The solution is to run the container tools in a container. For example, this is useful for running the latest version of the container tools provided in Red Hat Enterprise Linux 8 on a Red Hat Enterprise Linux 7 container host which does not have access to the newest versions natively.
HPC environment:
- All: A common restriction in HPC environments is that non-root users are not allowed to install packages on the host. When you run Skopeo, Buildah, or Podman in a container, you can perform these specific tasks as a non-root user.
17.1. Running Skopeo in a container Copy linkLink copied to clipboard!
You can inspect a remote container image using Skopeo. Running Skopeo in a container means that the container root filesystem is isolated from the host root filesystem. To share or copy files between the host and container, you have to mount files and directories.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Log in to the registry.redhat.io registry:
podman login registry.redhat.io
$ podman login registry.redhat.io Username: myuser@mycompany.com Password: <password> Login Succeeded!Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get the
registry.redhat.io/rhel10/skopeocontainer image:podman pull registry.redhat.io/rhel10/skopeo
$ podman pull registry.redhat.io/rhel10/skopeoCopy to Clipboard Copied! Toggle word wrap Toggle overflow Inspect a remote container image
registry.access.redhat.com/ubi10/ubiusing Skopeo:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
--rmoption removes theregistry.redhat.io/rhel10/skopeoimage after the container exits.
17.2. Running Skopeo in a container using credentials Copy linkLink copied to clipboard!
Working with container registries requires an authentication to access and alter data. Skopeo supports various ways to specify credentials.
With this approach you can specify credentials on the command line using the --cred USERNAME[:PASSWORD] option.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Inspect a remote container image using Skopeo against a locked registry:
podman run --rm registry.redhat.io/rhel10/skopeo inspect --creds $USER:$PASSWORD docker://$IMAGE
$ podman run --rm registry.redhat.io/rhel10/skopeo inspect --creds $USER:$PASSWORD docker://$IMAGECopy to Clipboard Copied! Toggle word wrap Toggle overflow
17.3. Running Skopeo in a container using authfiles Copy linkLink copied to clipboard!
You can use an authentication file (authfile) to specify credentials. The skopeo login command logs into the specific registry and stores the authentication token in the authfile. The advantage of using authfiles is preventing the need to repeatedly enter credentials.
When running on the same host, all container tools such as Skopeo, Buildah, and Podman share the same authfile. When running Skopeo in a container, you have to either share the authfile on the host by volume-mounting the authfile in the container, or you have to reauthenticate within the container.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Inspect a remote container image using Skopeo against a locked registry:
podman run --rm -v $AUTHFILE:/auth.json registry.redhat.io/rhel10/skopeo inspect docker://$IMAGE
$ podman run --rm -v $AUTHFILE:/auth.json registry.redhat.io/rhel10/skopeo inspect docker://$IMAGECopy to Clipboard Copied! Toggle word wrap Toggle overflow The
-v $AUTHFILE:/auth.jsonoption volume-mounts an authfile at /auth.json within the container. Skopeo can now access the authentication tokens in the authfile on the host and get secure access to the registry.
The other Skopeo commands work similarly, for example:
-
Use the
skopeo-copycommand to specify credentials on the command line for the source and destination image using the--source-credsand--dest-credsoptions. It also reads the/auth.jsonauthfile. -
If you want to specify separate authfiles for the source and destination image, use the
--source-authfileand--dest-authfileoptions and volume-mount those authfiles from the host into the container.
17.4. Copying container images to or from the host Copy linkLink copied to clipboard!
Skopeo, Buildah, and Podman share the same local container-image storage. If you want to copy containers to or from the host container storage, you need to mount it into the Skopeo container.
The path to the host container storage differs between root (/var/lib/containers/storage) and non-root users ($HOME/.local/share/containers/storage).
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Copy the
registry.access.redhat.com/ubi10/ubiimage into your local container storage:podman run --privileged --rm -v $HOME/.local/share/containers/storage:/var/lib/containers/storage \ registry.redhat.io/rhel10/skopeo skopeo copy \ docker://registry.access.redhat.com/ubi10/ubi containers-storage:registry.access.redhat.com/ubi10/ubi
$ podman run --privileged --rm -v $HOME/.local/share/containers/storage:/var/lib/containers/storage \ registry.redhat.io/rhel10/skopeo skopeo copy \ docker://registry.access.redhat.com/ubi10/ubi containers-storage:registry.access.redhat.com/ubi10/ubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
--privilegedoption disables all security mechanisms. Red Hat recommends only using this option in trusted environments. To avoid disabling security mechanisms, export the images to a tarball or any other path-based image transport and mount them in the Skopeo container:
-
$ podman save --format oci-archive -o oci.tar $IMAGE -
$ podman run --rm -v oci.tar:/oci.tar registry.redhat.io/rhel10/skopeo copy oci-archive:/oci.tar $DESTINATION
-
-
The
Optional: List images in local storage:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.access.redhat.com/ubi10/ubi latest ecbc6f53bba0 8 weeks ago 211 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow
17.5. Running Buildah in a container Copy linkLink copied to clipboard!
The procedure demonstrates how to run Buildah in a container and create a working container based on an image.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Log in to the registry.redhat.io registry:
podman login registry.redhat.io
$ podman login registry.redhat.io Username: myuser@mycompany.com Password: <password> Login Succeeded!Copy to Clipboard Copied! Toggle word wrap Toggle overflow Pull and run the
registry.redhat.io/rhel10/buildahimage:podman run --rm --device /dev/fuse -it \ registry.redhat.io/rhel10/buildah /bin/bash
# podman run --rm --device /dev/fuse -it \ registry.redhat.io/rhel10/buildah /bin/bashCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
--rmoption removes theregistry.redhat.io/rhel10/buildahimage after the container exits. -
The
--deviceoption adds a host device to the container. -
The
sys_chroot- capability to change to a different root directory. It is not included in the default capabilities of a container.
-
The
Create a new container using a
registry.access.redhat.com/ubi10/image:buildah from registry.access.redhat.com/ubi10/
# buildah from registry.access.redhat.com/ubi10/ ... ubi10/-working-containerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the
ls /command inside theubi10/-working-containercontainer:buildah run --isolation=chroot ubi10/-working-container ls /
# buildah run --isolation=chroot ubi10/-working-container ls / bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srvCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all images in a local storage:
buildah images
# buildah images REPOSITORY TAG IMAGE ID CREATED SIZE registry.access.redhat.com/ubi10/ latest ecbc6f53bba0 5 weeks ago 211 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List the working containers and their base images:
buildah containers
# buildah containers CONTAINER ID BUILDER IMAGE ID IMAGE NAME CONTAINER NAME 0aaba7192762 * ecbc6f53bba0 registry.access.redhat.com/ub... ubi10/-working-containerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Push the
registry.access.redhat.com/ubi10/image to the a local registry located onregistry.example.com:buildah push ecbc6f53bba0 registry.example.com:5000/ubi10/ubi
# buildah push ecbc6f53bba0 registry.example.com:5000/ubi10/ubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow
17.6. Privileged and unprivileged Podman containers Copy linkLink copied to clipboard!
By default, Podman containers are unprivileged and cannot, for example, modify parts of the operating system on the host. This is because by default a container is only allowed limited access to devices.
The following list emphasizes important properties of privileged containers. You can run the privileged container by using the podman run --privileged <image_name> command.
- A privileged container is given the same access to devices as the user launching the container.
- A privileged container disables the security features that isolate the container from the host. Dropped Capabilities, limited devices, read-only mount points, Apparmor/SELinux separation, and Seccomp filters are all disabled.
- A privileged container cannot have more privileges than the account that launched them.
17.7. Running Podman with extended privileges Copy linkLink copied to clipboard!
If you cannot run your workloads in a rootless environment, you need to run these workloads as a root user. Running a container with extended privileges should be done judiciously, because it disables all security features.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Run the Podman container in the Podman container:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Run the outer container named
privileged_podmanbased on theregistry.access.redhat.com/ubi10/podmanimage. -
The
--privilegedoption disables the security features that isolate the container from the host. -
Run
podman run ubi10 echo hellocommand to create the inner container based on theubi10image. -
Notice that the
ubi10short image name was resolved as an alias. As a result, theregistry.access.redhat.com/ubi10:latestimage is pulled.
Verification
List all containers:
podman ps -a
$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 52537876caf4 registry.access.redhat.com/ubi10/podman podman run ubi10 e... 30 seconds ago Exited (0) 13 seconds ago privileged_podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-run(1)man page on your system.
17.8. Running Podman with less privileges Copy linkLink copied to clipboard!
You can run two nested Podman containers without the --privileged option. Running the container without the --privileged option is a more secure option.
This can be useful when you want to try out different versions of Podman in the most secure way possible.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Run two nested containers:
podman run --name=unprivileged_podman --security-opt label=disable \ --user podman --device /dev/fuse \ registry.access.redhat.com/ubi10/podman \ podman run ubi10 echo hello
$ podman run --name=unprivileged_podman --security-opt label=disable \ --user podman --device /dev/fuse \ registry.access.redhat.com/ubi10/podman \ podman run ubi10 echo helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Run the outer container named
unprivileged_podmanbased on theregistry.access.redhat.com/ubi10/podmanimage. -
The
--security-opt label=disableoption disables SELinux separation on the host Podman. SELinux does not allow containerized processes to mount all of the file systems required to run inside a container. -
The
--user podmanoption automatically causes the Podman inside the outer container to run within the user namespace. -
The
--device /dev/fuseoption uses thefuse-overlayfspackage inside the container. This option adds/dev/fuseto the outer container, so that Podman inside the container can use it. -
Run
podman run ubi10 echo hellocommand to create the inner container based on theubi10image. -
Notice that the ubi10 short image name was resolved as an alias. As a result, the
registry.access.redhat.com/ubi10:latestimage is pulled.
Verification
List all containers:
podman ps -a
$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a47b26290f43 podman run ubi10 e... 30 seconds ago Exited (0) 13 seconds ago unprivileged_podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
17.9. Building a container inside a Podman container Copy linkLink copied to clipboard!
You can run a container in a container using Podman. This example shows how to use Podman to build and run another container from within this container. The container will run "Moon-buggy", a simple text-based game.
Prerequisites
-
The
container-toolsmeta-package is installed. You are logged in to the registry.redhat.io registry:
podman login registry.redhat.io
# podman login registry.redhat.ioCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Run the container based on
registry.redhat.io/rhel10/podmanimage:podman run --privileged --name podman_container -it \ registry.redhat.io/rhel10/podman /bin/bash
# podman run --privileged --name podman_container -it \ registry.redhat.io/rhel10/podman /bin/bashCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Run the outer container named
podman_containerbased on theregistry.redhat.io/rhel10/podmanimage. -
The
--itoption specifies that you want to run an interactive bash shell within a container. -
The
--privilegedoption disables the security features that isolate the container from the host.
-
Run the outer container named
Create a
Containerfileinside thepodman_containercontainer:vi Containerfile
# vi Containerfile FROM registry.access.redhat.com/ubi10/ubi RUN dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm RUN dnf -y install moon-buggy && dnf clean all CMD ["/usr/bin/moon-buggy"]Copy to Clipboard Copied! Toggle word wrap Toggle overflow The commands in the
Containerfilecause the following build command to:-
Build a container from the
registry.access.redhat.com/ubi10/ubiimage. -
Install the
epel-release-latest-8.noarch.rpmpackage. -
Install the
moon-buggypackage. - Set the container command.
-
Build a container from the
Build a new container image named
moon-buggyusing theContainerfile:podman build -t moon-buggy .
# podman build -t moon-buggy .Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all images:
podman images
# podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/moon-buggy latest c97c58abb564 13 seconds ago 1.67 GB registry.access.redhat.com/ubi10/ubi latest 4199acc83c6a 132seconds ago 213 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run a new container based on a
moon-buggycontainer:podman run -it --name moon moon-buggy
# podman run -it --name moon moon-buggyCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Tag the
moon-buggyimage:podman tag moon-buggy registry.example.com/moon-buggy
# podman tag moon-buggy registry.example.com/moon-buggyCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Push the
moon-buggyimage to the registry:podman push registry.example.com/moon-buggy
# podman push registry.example.com/moon-buggyCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Chapter 18. Monitoring containers Copy linkLink copied to clipboard!
Use Podman commands to manage a Podman environment. With that, you can determine the health of the container, by displaying system and pod information, and monitoring Podman events.
18.1. Using a health check on a container Copy linkLink copied to clipboard!
You can use the health check to determine the health or readiness of the process running inside the container.
If the health check succeeds, the container is marked as "healthy"; otherwise, it is "unhealthy". You can compare a health check with running the podman exec command and examining the exit code. The zero exit value means that the container is "healthy".
Health checks can be set when building an image using the HEALTHCHECK instruction in the Containerfile or when creating the container on the command line. You can display the health-check status of a container by using the podman inspect or podman ps commands.
A health check consists of six basic components:
- Command
- Retries
- Interval
- Start-period
- Timeout
- Container recovery
The description of health check components follows:
- Command (
--health-cmdoption) - Podman executes the command inside the target container and waits for the exit code.
The other five components are related to the scheduling of the health check and they are optional.
- Retries (
--health-retriesoption) - Defines the number of consecutive failed health checks that need to occur before the container is marked as "unhealthy". A successful health check resets the retry counter.
- Interval (
--health-intervaloption) - Describes the time between running the health check command. Note that small intervals cause your system to spend a lot of time running health checks. The large intervals cause struggles with catching time outs.
- Start-period (
--health-start-periodoption) - Describes the time between when the container starts and when you want to ignore health check failures.
- Timeout (
--health-timeoutoption) - Describes the period of time the health check must complete before being considered unsuccessful.
The values of the Retries, Interval, and Start-period components are time durations, for example "30s” or "1h15m”. Valid time units are "ns," "us," or "µs", "ms," "s," "m," and "h".
- Container recovery (
--health-on-failureoption) Determines which actions to perform when the status of a container is unhealthy. When the application fails, Podman restarts it automatically to provide robustness. The
--health-on-failureoption supports four actions:-
none: Take no action, this is the default action. -
kill: Kill the container. -
restart: Restart the container. stop: Stop the container.NoteThe
--health-on-failureoption is available in Podman version 4.2 and later.
-
Do not combine the restart action with the --restart option. When running inside of a systemd unit, consider using the kill or stop action instead, to make use of systemd restart policy.
Health checks run inside the container. Health checks only make sense if you know what the health state of the service is and can differentiate between a successful and unsuccessful health check.
For more information, see the podman-healthcheck(1) and podman-run(1) man pages on your system.
18.2. Performing a health check using the command line Copy linkLink copied to clipboard!
You can set a health check when creating the container on the command line.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Define a health check:
podman run -dt --name=hc-container -p 8080:8080 --health-cmd='curl http://localhost:8080 || exit 1' --health-interval=0 registry.access.redhat.com/ubi8/httpd-24
$ podman run -dt --name=hc-container -p 8080:8080 --health-cmd='curl http://localhost:8080 || exit 1' --health-interval=0 registry.access.redhat.com/ubi8/httpd-24Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
--health-cmdoption sets a health check command for the container. -
The
--health-interval=0option with 0 value indicates that you want to run the health check manually.
-
The
Check the health status of the
hc-containercontainer:Using the
podman inspectcommand:podman inspect --format='{{json .State.Health.Status}}' hc-container$ podman inspect --format='{{json .State.Health.Status}}' hc-container healthyCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using the
podman pscommand:podman ps
$ podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a680c6919fe localhost/hc-container:latest /usr/bin/run-http... 2 minutes ago Up 2 minutes (healthy) hc-containerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using the
podman healthcheck runcommand:podman healthcheck run hc-container
$ podman healthcheck run hc-container healthyCopy to Clipboard Copied! Toggle word wrap Toggle overflow
18.3. Performing a health check using a Containerfile Copy linkLink copied to clipboard!
You can set a health check by using the HEALTHCHECK instruction in the Containerfile.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create a
Containerfile:cat Containerfile FROM registry.access.redhat.com/ubi8/httpd-24 EXPOSE 8080 HEALTHCHECK CMD curl http://localhost:8080 || exit 1
$ cat Containerfile FROM registry.access.redhat.com/ubi8/httpd-24 EXPOSE 8080 HEALTHCHECK CMD curl http://localhost:8080 || exit 1Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe
HEALTHCHECKinstruction is supported only for thedockerimage format. For theociimage format, the instruction is ignored.Build the container and add an image name:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the container:
podman run -dt --name=hc-container localhost/hc-container
$ podman run -dt --name=hc-container localhost/hc-containerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Check the health status of the
hc-containercontainer:Using the
podman inspectcommand:podman inspect --format='{{json .State.Health.Status}}' hc-container$ podman inspect --format='{{json .State.Health.Status}}' hc-container healthyCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using the
podman pscommand:podman ps
$ podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a680c6919fe localhost/hc-container:latest /usr/bin/run-http... 2 minutes ago Up 2 minutes (healthy) hc-containerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using the
podman healthcheck runcommand:podman healthcheck run hc-container
$ podman healthcheck run hc-container healthyCopy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see
podman-healthcheck(1)andpodman-run(1)man pages on your system.
18.4. Displaying Podman system information Copy linkLink copied to clipboard!
The podman system command enables you to manage the Podman systems by displaying system information.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Display Podman system information:
To show Podman disk usage, enter:
podman system df
$ podman system df TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 3 2 1.085GB 233.4MB (0%) Containers 2 0 28.17kB 28.17kB (100%) Local Volumes 3 0 0B 0B (0%)Copy to Clipboard Copied! Toggle word wrap Toggle overflow To show detailed information about space usage, enter:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To display information about the host, current storage stats, and build of Podman, enter:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To remove all unused containers, images and volume data, enter:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
podman system prunecommand removes all unused containers (both dangling and unreferenced), pods and optionally, volumes from local storage. -
Use the
--alloption to delete all unused images. Unused images are dangling images and any image that does not have any containers based on it. Use the
--volumeoption to prune volumes. By default, volumes are not removed to prevent important data from being deleted if there is currently no container using the volume.For more information, see the
podman-system-df,podman-system-info, andpodman-system-pruneman pages on your system.
-
The
18.5. Podman event types Copy linkLink copied to clipboard!
You can monitor events that occur in Podman. Several event types exist and each event type reports different statuses.
The container event type reports the following statuses:
- attach
- checkpoint
- cleanup
- commit
- create
- exec
- export
- import
- init
- kill
- mount
- pause
- prune
- remove
- restart
- restore
- start
- stop
- sync
- unmount
- unpause
The pod event type reports the following statuses:
- create
- kill
- pause
- remove
- start
- stop
- unpause
The image event type reports the following statuses:
- prune
- push
- pull
- save
- remove
- tag
- untag
The system type reports the following statuses:
- refresh
- renumber
The volume type reports the following statuses:
- create
- prune
remove
For more information, see the
podman-events(1)man page on your system.
18.6. Monitoring Podman events Copy linkLink copied to clipboard!
You can monitor and print events that occur in Podman by using the podman events command. Each event will include a timestamp, a type, a status, name, if applicable, and image, if applicable.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Run the
myubicontainer:podman run -q --rm --name=myubi registry.access.redhat.com/ubi8/ubi:latest
$ podman run -q --rm --name=myubi registry.access.redhat.com/ubi8/ubi:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow Display the Podman events:
To display all Podman events, enter:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
--stream=falseoption ensures that thepodman eventscommand exits when reading the last known event.You can see several events that happened when you enter the
podman runcommand:-
container createwhen creating a new container. -
image pullwhen pulling an image if the container image is not present in the local storage. -
container initwhen initializing the container in the runtime and setting a network. -
container startwhen starting the container. -
container attachwhen attaching to the terminal of a container. That is because the container runs in the foreground. -
container diedis emitted when the container exits. -
container removebecause the--rmflag was used to remove the container after it exits.
-
You can also use the
journalctlcommand to display Podman events:journalctl --user -r SYSLOG_IDENTIFIER=podman
$ journalctl --user -r SYSLOG_IDENTIFIER=podman Mar 08 14:27:20 fedora podman[129324]: 2023-03-08 14:27:20.913786892 +0100 CET m=+0.066920979 container remove ... Mar 08 14:27:20 fedora podman[129289]: 2023-03-08 14:27:20.696167362 +0100 CET m=+0.079089208 container create d4748226a2bcd271b1bc4b9f88b54e8271c13ffea9b30529968291c62d72f>Copy to Clipboard Copied! Toggle word wrap Toggle overflow To show only Podman create events, enter:
podman events --filter event=create
$ podman events --filter event=create 2023-03-08 14:27:20.696167362 +0100 CET container create d4748226a2bcd271b1bc4b9f88b54e8271c13ffea9b30529968291c62d72fe09 (image=registry.access.redhat.com/ubi8/ubi:latest, name=myubi,...)Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can also use the
journalctlcommand to display Podman create events:journalctl --user -r PODMAN_EVENT=create
$ journalctl --user -r PODMAN_EVENT=create Mar 08 14:27:20 fedora podman[129289]: 2023-03-08 14:27:20.696167362 +0100 CET m=+0.079089208 container create d4748226a2bcd271b1bc4b9f88b54e8271c13ffea9b30529968291c62d72f>Copy to Clipboard Copied! Toggle word wrap Toggle overflow For more information, see the
podman-events(1)man page on your system.
18.7. Using Podman events for auditing Copy linkLink copied to clipboard!
Previously, the events had to be connected to an event to interpret them correctly. For example, the container-create event had to be linked with an image-pull event to know which image had been used. The container-create event also did not include all data, for example, the security settings, volumes, mounts, and so on.
Beginning with Podman v4.4, you can gather all relevant information about a container directly from a single event and journald entry. The data is in JSON format, the same as from the podman container inspect command and includes all configuration and security settings of a container. You can configure Podman to attach the container-inspect data for auditing purposes.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Modify the
~/.config/containers/containers.conffile and add theevents_container_create_inspect_data=trueoption to the[engine]section:cat ~/.config/containers/containers.conf [engine] events_container_create_inspect_data=true
$ cat ~/.config/containers/containers.conf [engine] events_container_create_inspect_data=trueCopy to Clipboard Copied! Toggle word wrap Toggle overflow For the system-wide configuration, modify the
/etc/containers/containers.confor/usr/share/container/containers.conffile.Create the container:
podman create registry.access.redhat.com/ubi8/ubi:latest
$ podman create registry.access.redhat.com/ubi8/ubi:latest 19524fe3c145df32d4f0c9af83e7964e4fb79fc4c397c514192d9d7620a36cd3Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display the Podman events:
Using the
podman eventscommand:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
--format "{{.ContainerInspectData}}"option displays the inspect data. -
The
jq ".Config.CreateCommand"transforms the JSON data into a more readable format and displays the parameters for thepodman createcommand.
-
The
Using the
journalctlcommand:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The output data for the
podman eventsandjournalctlcommands are the same.For more information, see the
podman-events(1)andcontainers.conf(5)man pages on your system.
Chapter 19. Using Toolbx for development and troubleshooting Copy linkLink copied to clipboard!
Installing software on a system presents certain risks: it can change a system’s behavior, and can leave unwanted files and directories behind after they are no longer needed. You can prevent these risks by installing your favorite development and debugging tools, editors, and software development kits (SDKs) into the Toolbx fully mutable container without affecting the base operating system. You can perform changes on the host system with commands such as less, lsof, rsync, ssh, sudo, and unzip.
The Toolbx utility performs the following actions:
-
Pulling the
registry.access.redhat.com/ubi10/toolbox:latestimage to your local system - Starting up a container from the image
- Running a shell inside the container from which you can access the host system
Toolbx can run a root container or a rootless container, depending on the rights of the user who creates the Toolbx container. Utilities that would require root rights on the host system also should be run in root containers.
The default container name is rhel-toolbox.
19.1. Starting a Toolbx container Copy linkLink copied to clipboard!
You can create a Toolbx container by using the toolbox create command. You can then enter the container with the toolbox enter command.
Procedure
Create a Toolbx container:
As a rootless user:
toolbox create <mytoolbox>
$ toolbox create <mytoolbox> Created container: <mytoolbox> Enter with: toolbox enter <mytoolbox>Copy to Clipboard Copied! Toggle word wrap Toggle overflow As a root user:
sudo toolbox create <mytoolbox>
$ sudo toolbox create <mytoolbox> Created container: <mytoolbox> Enter with: toolbox enter <mytoolbox>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that you pulled the correct image:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Enter the Toolbx container:
toolbox enter <mytoolbox>
[user@toolbox ~]$ toolbox enter <mytoolbox>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Enter a command inside the
<mytoolbox>container and display the name of the container and the image:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
19.2. Using Toolbx for development Copy linkLink copied to clipboard!
You can use a Toolbx container as a rootless user for installation of development tools, such as editors, compilers, and software development kits (SDKs). After installation, you can continue using those tools as a rootless user.
Prerequisites
- The Toolbx container is created and is running. You entered the Toolbx container. You do not need to create the Toolbx container with root privileges. See Starting a Toolbox container.
Procedure
Install the tools of your choice, for example, the Emacs text editor, GCC compiler and GNU Debugger (GDB):
⬢[user@toolbox ~]$ sudo dnf install emacs gcc gdb
⬢[user@toolbox ~]$ sudo dnf install emacs gcc gdbCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify that the tools are installed:
⬢[user@toolbox ~]$ dnf repoquery --info --installed <package_name>
⬢[user@toolbox ~]$ dnf repoquery --info --installed <package_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
19.3. Using Toolbx for troubleshooting a host system Copy linkLink copied to clipboard!
You can use a Toolbx container with root privileges to find the root cause of various problems with the host system by using tools such as systemd, journalctl , and nmap, without installing them on the host system. Inside the Toolbx container you can, for example, perform the following actions.
Prerequisites
- The Toolbx container is created and is running. You entered the Toolbx container. You need to create the Toolbx container with root privileges. See Starting a Toolbox container.
Procedure
Install the
systemdsuite to be able to run thejournalctlcommand:⬢[root@toolbox ~]# dnf install systemd
⬢[root@toolbox ~]# dnf install systemdCopy to Clipboard Copied! Toggle word wrap Toggle overflow Display log messages for all processes running on the host:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display log messages for the kernel:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Install the
nmapnetwork scanning tool:⬢[root@toolbox ~]# dnf install nmap
⬢[root@toolbox ~]# dnf install nmapCopy to Clipboard Copied! Toggle word wrap Toggle overflow Scan IP addresses and ports in a network:
⬢[root@toolbox ~]# nmap -sS scanme.nmap.org Starting Nmap 7.93 ( https://nmap.org ) at 2024-01-02 10:39 CET Stats: 0:01:01 elapsed; 0 hosts completed (0 up), 256 undergoing Ping Scan Ping Scan Timing: About 29.79% done; ETC: 10:43 (0:02:24 remaining) Nmap done: 256 IP addresses (0 hosts up) scanned in 206.45 seconds
⬢[root@toolbox ~]# nmap -sS scanme.nmap.org Starting Nmap 7.93 ( https://nmap.org ) at 2024-01-02 10:39 CET Stats: 0:01:01 elapsed; 0 hosts completed (0 up), 256 undergoing Ping Scan Ping Scan Timing: About 29.79% done; ETC: 10:43 (0:02:24 remaining) Nmap done: 256 IP addresses (0 hosts up) scanned in 206.45 secondsCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
-sSoption performs a TCP SYN scan. Most of Nmap’s scan types are only available to privileged users, because they send and receive raw packets, which requires root access on UNIX systems.
-
The
19.4. Stopping the Toolbx container Copy linkLink copied to clipboard!
Use the exit command to leave the Toolbox container and the podman stop command to stop the container.
Procedure
Leave the container and return to the host:
⬢ [user@toolbox ~]$ exit
⬢ [user@toolbox ~]$ exitCopy to Clipboard Copied! Toggle word wrap Toggle overflow Stop the toolbox container:
⬢ [user@toolbox ~]$ podman stop <mytoolbox>
⬢ [user@toolbox ~]$ podman stop <mytoolbox>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Remove the toolbox container:
⬢ [user@toolbox ~]$ toolbox rm <mytoolbox>
⬢ [user@toolbox ~]$ toolbox rm <mytoolbox>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, you can also use the
podman rmcommand to remove the container.
Chapter 20. Running special container images Copy linkLink copied to clipboard!
You can run some special types of container images. Some container images have built-in labels called runlabels that enable you to run those containers with preset options and arguments. The podman container runlabel <label> command, you can execute the command defined in the <label> for the container image. Supported labels are install, run and uninstall.
20.1. Opening privileges to the host Copy linkLink copied to clipboard!
There are several differences between privileged and non-privileged containers. For example, the toolbox container is a privileged container. Here are examples of privileges that may or may not be open to the host from a container:
-
Privileges: A privileged container disables the security features that isolate the container from the host. You can run a privileged container by using the
podman run --privileged <image_name>command. You can, for example, delete files and directories mounted from the host that are owned by the root user. -
Process tables: You can use the
podman run --privileged --pid=host <image_name>command to use the host PID namespace for the container. Then you can use theps -ecommand within a privileged container to list all processes running on the host. You can pass a process ID from the host to commands that run in the privileged container (for example,kill <PID>). -
Network interfaces: By default, a container has only one external network interface and one loopback network interface. You can use the
podman run --net=host <image_name>command to access host network interfaces directly from within the container. -
Inter-process communications: The IPC facility on the host is accessible from within the privileged container. You can run commands such as
ipcsto see information about active message queues, shared memory segments, and semaphore sets on the host.
20.2. Container images with runlabels Copy linkLink copied to clipboard!
Some Red Hat images include labels that provide pre-set command lines for working with those images. With podman container runlabel <label> command, you can use the podman command to execute the command defined in the <label> for the image.
Existing runlabels include:
- install: Sets up the host system before executing the image. Typically, this results in creating files and directories on the host that the container can access when it is run later.
- run: Identifies podman command line options to use when running the container. Typically, the options will open privileges on the host and mount the host content the container needs to remain permanently on the host.
- uninstall: Cleans up the host system after you finish running the container.
20.3. Running support-tools with runlabels Copy linkLink copied to clipboard!
The rhel10/support-tools container image is made to run a containerized version of the support-toolsd daemon. The support-tools image contains the following runlabels: install, run and uninstall. The following procedure steps you through installing, running, and uninstalling the support-tools image:
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Pull the
support-toolsimage:podman pull registry.redhat.io/rhel10/support-tools
# podman pull registry.redhat.io/rhel10/support-toolsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Display the
installrunlabel forsupport-tools:podman container runlabel install --display rhel10/support-tools
# podman container runlabel install --display rhel10/support-tools command: podman run --rm --privileged -v /:/host -e HOST=/host -e IMAGE=registry.redhat.io/rhel10/support-tools:latest -e NAME=support-tools registry.redhat.io/rhel10/support-tools:latest /bin/install.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow This shows that the command will open privileges to the host, mount the host root filesystem on
/hostin the container, and run aninstall.shscript.Run the
installrunlabel forsupport-tools:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This creates files on the host system that the
support-toolsimage will use later.Display the
runrunlabel forsupport-tools:podman container runlabel run --display rhel10/support-tools
# podman container runlabel run --display rhel10/support-tools command: podman run -d --privileged --name support-tools --net=host --pid=host -v /etc/pki/support-tools:/etc/pki/support-tools -v /etc/support-tools.conf:/etc/support-tools.conf -v /etc/sysconfig/support-tools:/etc/sysconfig/support-tools -v /etc/support-tools.d:/etc/support-tools.d -v /var/log:/var/log -v /var/lib/support-tools:/var/lib/support-tools -v /run:/run -v /etc/machine-id:/etc/machine-id -v /etc/localtime:/etc/localtime -e IMAGE=registry.redhat.io/rhel10/support-tools:latest -e NAME=support-tools --restart=always registry.redhat.io/rhel10/support-tools:latest /bin/support-tools.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow This shows that the command opens privileges to the host and mount specific files and directories from the host inside the container, when it launches the
support-toolscontainer to run thesupport-toolsddaemon.Execute the
runrunlabel forsupport-tools:podman container runlabel run rhel10/support-tools
# podman container runlabel run rhel10/support-tools command: podman run -d --privileged --name support-tools --net=host --pid=host -v /etc/pki/support-tools:/etc/pki/support-tools -v /etc/support-tools.conf:/etc/support-tools.conf -v /etc/sysconfig/support-tools:/etc/sysconfig/support-tools -v /etc/support-tools.d:/etc/support-tools.d -v /var/log:/var/log -v /var/lib/support-tools:/var/lib/support-tools -v /run:/run -v /etc/machine-id:/etc/machine-id -v /etc/localtime:/etc/localtime -e IMAGE=registry.redhat.io/rhel10/support-tools:latest -e NAME=support-tools --restart=always registry.redhat.io/rhel10/support-tools:latest /bin/support-tools.sh 28a0d719ff179adcea81eb63cc90fcd09f1755d5edb121399068a4ea59bd0f53Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
support-toolscontainer opens privileges, mounts what it needs from the host, and runs thesupport-toolsddaemon in the background (-d). Thesupport-toolsddaemon begins gathering log messages and directing messages to files in the/var/logdirectory.Display the
uninstallrunlabel forsupport-tools:podman container runlabel uninstall --display rhel10/support-tools
# podman container runlabel uninstall --display rhel10/support-tools command: podman run --rm --privileged -v /:/host -e HOST=/host -e IMAGE=registry.redhat.io/rhel10/support-tools:latest -e NAME=support-tools registry.redhat.io/rhel10/support-tools:latest /bin/uninstall.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the
uninstallrunlabel forsupport-tools:podman container runlabel uninstall rhel10/support-tools
# podman container runlabel uninstall rhel10/support-tools command: podman run --rm --privileged -v /:/host -e HOST=/host -e IMAGE=registry.redhat.io/rhel10/support-tools:latest -e NAME=support-tools registry.redhat.io/rhel10/support-tools:latest /bin/uninstall.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow
In this case, the uninstall.sh script just removes the /etc/logrotate.d/syslog file. It does not clean up the configuration files.
Chapter 21. Using the container-tools API Copy linkLink copied to clipboard!
The new REST based Podman 2.0 API replaces the old remote API for Podman that used the varlink library. The new API works in both a rootful and a rootless environment.
The Podman v2.0 RESTful API consists of the Libpod API providing support for Podman, and Docker-compatible API. With this new REST API, you can call Podman from platforms such as cURL, Postman, Google’s Advanced REST client, and many others.
As the podman service supports socket activation, unless connections on the socket are active, podman service will not run. Hence, to enable socket activation functionality, you need to manually start the podman.socket service. When a connection becomes active on the socket, it starts the podman service and runs the requested API action. Once the action is completed, the podman process ends, and the podman service returns to an inactive state.
21.1. Enabling the Podman API using systemd in root mode Copy linkLink copied to clipboard!
You can do the following:
-
Use
systemdto activate the Podman API socket. - Use a Podman client to perform basic commands.
Prerequisites
The
podman-remotepackage is installed.dnf install podman-remote
# dnf install podman-remoteCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Start the service immediately:
systemctl enable --now podman.socket
# systemctl enable --now podman.socketCopy to Clipboard Copied! Toggle word wrap Toggle overflow To enable the link to
var/lib/docker.sockby using thedocker-podmanpackage:dnf install podman-docker
# dnf install podman-dockerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Display system information of Podman:
podman-remote info
# podman-remote infoCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the link:
ls -al /var/run/docker.sock
# ls -al /var/run/docker.sock lrwxrwxrwx. 1 root root 23 Nov 4 10:19 /var/run/docker.sock -> /run/podman/podman.sockCopy to Clipboard Copied! Toggle word wrap Toggle overflow
21.2. Enabling the Podman API using systemd in rootless mode Copy linkLink copied to clipboard!
You can use systemd to activate the Podman API socket and podman API service.
Prerequisites
The
podman-remotepackage is installed.dnf install podman-remote
# dnf install podman-remoteCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Enable and start the service immediately:
systemctl --user enable --now podman.socket
$ systemctl --user enable --now podman.socketCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: To enable programs by using Docker to interact with the rootless Podman socket:
export DOCKER_HOST=unix:///run/user/<uid>/podman//podman.sock
$ export DOCKER_HOST=unix:///run/user/<uid>/podman//podman.sockCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Check the status of the socket:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
podman.socketis active and is listening at/run/user/<uid>/podman.podman.sock, where<uid>is the user’s ID.Display system information of Podman:
podman-remote info
$ podman-remote infoCopy to Clipboard Copied! Toggle word wrap Toggle overflow
21.3. Running the Podman API manually Copy linkLink copied to clipboard!
You can run the Podman API. This is useful for debugging API calls, especially when using the Docker compatibility layer.
Prerequisites
The
podman-remotepackage is installed.dnf install podman-remote
# dnf install podman-remoteCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Run the service for the REST API:
podman system service -t 0 --log-level=debug
# podman system service -t 0 --log-level=debugCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
The value of 0 means no timeout. The default endpoint for a rootful service is
unix:/run/podman/podman.sock. -
The
--log-level <level>option sets the logging level. The standard logging levels aredebug,info,warn,error,fatal, andpanic.
-
The value of 0 means no timeout. The default endpoint for a rootful service is
In another terminal, display system information of Podman. The
podman-remotecommand, unlike the regularpodmancommand, communicates through the Podman socket:podman-remote info
# podman-remote infoCopy to Clipboard Copied! Toggle word wrap Toggle overflow To troubleshoot the Podman API and display request and responses, use the
curlcomman. To get the information about the Podman installation on the Linux server in JSON format:Copy to Clipboard Copied! Toggle word wrap Toggle overflow A
jqutility is a command-line JSON processor.Pull the
registry.access.redhat.com/ubi8/ubicontainer image:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display the pulled image:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow