Red Hat8-Building Running and Managing containers-en-US
Red Hat8-Building Running and Managing containers-en-US
Red Hat8-Building Running and Managing containers-en-US
Building, running, and managing Linux containers on Red Hat Enterprise Linux 8
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons
Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is
available at
http://creativecommons.org/licenses/by-sa/3.0/
. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must
provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert,
Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift,
Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States
and other countries.
Linux ® is the registered trademark of Linus Torvalds in the United States and other countries.
XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States
and/or other countries.
MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and
other countries.
Node.js ® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the
official Joyent Node.js open source or commercial project.
The OpenStack ® Word Mark and OpenStack logo are either registered trademarks/service marks
or trademarks/service marks of the OpenStack Foundation, in the United States and other
countries and are used with the OpenStack Foundation's permission. We are not affiliated with,
endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
Abstract
This guide describes how to work with Linux containers on RHEL 8 systems using command-line
tools such as podman, buildah, skopeo and runc.
Table of Contents
Table of Contents
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . .
PREFACE
. . . . . . . . . . . . . FEEDBACK
PROVIDING . . . . . . . . . . . . ON
. . . .RED
. . . . .HAT
. . . . .DOCUMENTATION
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5. . . . . . . . . . . . .
.CHAPTER
. . . . . . . . . . 1.. .STARTING
. . . . . . . . . . . WITH
. . . . . . CONTAINERS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6. . . . . . . . . . . . .
1.1. RUNNING CONTAINERS WITHOUT DOCKER 6
1.2. CHOOSING A RHEL ARCHITECTURE FOR CONTAINERS 7
1.3. GETTING CONTAINER TOOLS 7
1.4. ENABLING CONTAINER SETTINGS 8
1.5. RUNNING CONTAINERS AS ROOT OR ROOTLESS 9
1.5.1. Set up for rootless containers 9
1.5.2. Upgrade to rootless containers 10
1.5.3. Special considerations for rootless 11
.CHAPTER
. . . . . . . . . . 2.
. . WORKING
. . . . . . . . . . . WITH
. . . . . . CONTAINER
. . . . . . . . . . . . . .IMAGES
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
..............
2.1. PULLING IMAGES FROM REGISTRIES 13
2.2. INVESTIGATING IMAGES 14
2.2.1. Listing images 14
2.2.2. Inspecting local images 14
2.2.3. Inspecting remote images 16
2.3. SEARCHING FOR IMAGES 16
2.4. TAGGING IMAGES 18
2.5. SAVING AND LOADING IMAGES 19
2.6. REMOVING IMAGES 19
. . . . . . . . . . . 3.
CHAPTER . . WORKING
. . . . . . . . . . . WITH
. . . . . . CONTAINERS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
..............
3.1. RUNNING CONTAINERS 21
3.2. INVESTIGATING RUNNING AND STOPPED CONTAINERS 23
3.2.1. Listing containers 23
3.2.2. Inspecting containers 23
3.2.3. Investigating within a container 24
3.3. STARTING AND STOPPING CONTAINERS 25
3.3.1. Starting containers 26
3.3.2. Stopping containers 26
3.4. REMOVING CONTAINERS 26
.CHAPTER
. . . . . . . . . . 4.
. . .USING
. . . . . . .RED
. . . . .HAT
. . . . .UNIVERSAL
. . . . . . . . . . . . BASE
. . . . . . .IMAGES
. . . . . . . . (STANDARD,
. . . . . . . . . . . . . . MINIMAL,
. . . . . . . . . . .AND
. . . . .RUNTIMES)
. . . . . . . . . . . . . . . . . . . .28
..............
4.1. WHAT ARE RED HAT BASE IMAGES? 28
4.1.1. Using standard Red Hat base images 28
4.1.2. Using minimal Red Hat base images 29
4.1.3. Using Init Red Hat base images 30
4.2. HOW ARE UBI IMAGES DIFFERENT? 30
4.3. GET UBI IMAGES 31
4.4. PULL UBI IMAGES 34
4.5. REDISTRIBUTING UBI IMAGES 34
4.6. RUN UBI IMAGES 34
4.7. ADD SOFTWARE TO A RUNNING UBI CONTAINER 35
4.7.1. Adding software to a UBI container (subscribed host) 35
4.7.2. Adding software inside the standard UBI container 35
4.7.3. Adding software inside the minimal UBI container 36
4.7.4. Adding software to a UBI container (unsubscribed host) 36
4.7.5. Build a UBI-based image 37
1
Red Hat Enterprise Linux 8 Building, running, and managing containers
.CHAPTER
. . . . . . . . . . 5.
. . RUNNING
. . . . . . . . . . . SPECIAL
. . . . . . . . . .CONTAINER
. . . . . . . . . . . . .IMAGES
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
..............
5.1. TROUBLESHOOTING CONTAINER HOSTS WITH TOOLBOX 41
5.1.1. Opening privileges to the host 43
5.2. RUNNING CONTAINERS WITH RUNLABELS 43
5.2.1. Running rsyslog with runlabels 44
5.2.2. Running support-tools with runlabels 45
.CHAPTER
. . . . . . . . . . 6.
. . .BUILDING
. . . . . . . . . . CONTAINER
. . . . . . . . . . . . . .IMAGES
. . . . . . . . .WITH
. . . . . .BUILDAH
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47
..............
6.1. UNDERSTANDING BUILDAH 47
6.1.1. Installing Buildah 48
6.2. GETTING IMAGES WITH BUILDAH 48
6.3. BUILDING AN IMAGE FROM A DOCKERFILE WITH BUILDAH 49
6.3.1. Running the image you built 49
6.3.2. Inspecting a container with Buildah 50
6.4. MODIFYING A CONTAINER TO CREATE A NEW IMAGE WITH BUILDAH 50
6.4.1. Using buildah mount to modify a container 51
6.4.2. Using buildah copy and buildah config to modify a container 51
6.5. CREATING IMAGES FROM SCRATCH WITH BUILDAH 52
6.6. REMOVING IMAGES OR CONTAINERS WITH BUILDAH 53
6.7. USING CONTAINER REGISTRIES WITH BUILDAH 54
6.7.1. Pushing containers to a private registry 54
6.7.2. Pushing containers to the Docker Hub 55
. . . . . . . . . . . 7.
CHAPTER . . RUNNING
. . . . . . . . . . . CONTAINERS
. . . . . . . . . . . . . . .AS
. . .SYSTEMD
. . . . . . . . . . .SERVICES
. . . . . . . . . . .WITH
. . . . . .PODMAN
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .57
..............
7.1. STARTING CONTAINERS WITH SYSTEMD 57
7.2. STARTING SERVICES WITHIN A CONTAINER USING SYSTEMD 58
. . . . . . . . . . . 8.
CHAPTER . . .CONTAINER
. . . . . . . . . . . . .COMMAND-LINE
. . . . . . . . . . . . . . . . . .REFERENCE
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .60
..............
8.1. PODMAN 60
8.1.1. Using podman commands 60
8.1.2. Trying basic podman commands 62
8.1.3. Pull a container image to the local system 62
8.1.4. List local container images 62
8.1.5. Inspect a container image 62
8.1.6. Run a container image 63
8.1.7. List containers that are running or have exited 63
8.1.8. Remove a container or image 63
8.1.9. Generate a Kube pod yaml or systemd unit file 63
8.1.10. Build a container 65
8.2. RUNC 65
8.2.1. Running containers with runc 65
8.3. SKOPEO 66
8.3.1. Inspecting container images with skopeo 67
8.3.2. Copying container images with skopeo 68
8.3.3. Getting image layers with skopeo 68
. . . . . . . . . . . 9.
CHAPTER . . .ADDITIONAL
. . . . . . . . . . . . . RESOURCES
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .69
..............
2
Table of Contents
3
Red Hat Enterprise Linux 8 Building, running, and managing containers
PREFACE
Red Hat classifies container use cases into two distinct groups: single node and multi-node, with multi-
node sometimes called distributed systems. OpenShift was built for multi-node systems, although
single-node, all-in-one installations are supported as well. Beyond OpenShift, however, it is useful to
have a small, nimble set of tools for working with containers.
The set of container tools we are referring to can be used in a single-node use case. However, you can
also wire these tools into existing build systems, CI/CD environments, and even use them to tackle
workload-specific use cases, such as big data. To target the single-node use case, Red Hat Enterprise
Linux (RHEL) 8 offers a set of tools to find, run, build, and share individual containers.
This guide describes how to work with Linux containers on RHEL 8 systems using command-line tools
such as podman, buildah, skopeo and runc. In addition to these tools, Red Hat provides base images, to
act as the foundation for your own images. Some of these base images target use cases ranging from
business applications (such as Node.js, PHP, Java, and Python) to infrastructure (such as logging, data
collection, and authentication).
4
PROVIDING FEEDBACK ON RED HAT DOCUMENTATION
For simple comments on specific passages, make sure you are viewing the documentation in the
Multi-page HTML format. Highlight the part of text that you want to comment on. Then, click
the Add Feedback pop-up that appears below the highlighted text, and follow the displayed
instructions.
3. Fill in the Description field with your suggestion for improvement. Include a link to the
relevant part(s) of documentation.
5
Red Hat Enterprise Linux 8 Building, running, and managing containers
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, enabling
secure multi-tenancy and reducing the potential for security exploits. All this is meant to provide you
with an environment to 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. However, there are times when you might want to build
and manage individual containers and container images outside of OpenShift. Tools provided to
perform those tasks that run directly on RHEL systems are described in this guide.
Unlike other container tools implementations, tools described here do not center around the monolithic
Docker container engine and docker command. Instead, we provide 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)
runc - For providing container run and build features to podman and buildah
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 list of supported container tools, see What container runtimes and
container management tools are supported?.
For a multi-node container platform, see OpenShift. Instead of relying on the single-node, daemonless
tools described in this document, OpenShift requires a daemon-based container engine. Please see
Using the CRI-O Container Engine for details.
The removal of Docker reflects a change in Red Hat’s way of thinking about how containers are handled:
In the enterprise, the focus is not on running individual containers from the command line. The
primary venue for running containers is a Kubernetes-based platform, such as OpenShift.
By repositioning OpenShift as the project for running containers, container engines like Docker
become just another component of OpenShift with no direct access by end users.
Because the container engine in OpenShift is not meant to be used directly, it can be
implemented with a limited feature set that focuses on doing everything that OpenShift needs,
without having to implement lots of standalone features.
Although Docker is gone from RHEL 8, and OpenShift’s container engine is disconnected from single-
6
CHAPTER 1. STARTING WITH CONTAINERS
Although Docker is gone from RHEL 8, and OpenShift’s container engine is disconnected from single-
node uses, people still want to use commands to work with containers and images manually. So Red Hat
set about to create a set of tools to implement most of what the docker command does.
Tools like podman, skopeo, and buildah were developed to take over those docker command features.
Each tool in this scenario can be more light-weight and focused on a subset of features. And with no
need for a daemon process running to implement a container engine, these tools can run without the
overhead of having to work with a daemon process.
If you feel that you still want to use Docker in RHEL 8, know that you can get Docker from different
upstream projects, but that its use is unsupported in RHEL 8. Because so many docker command-line
features have been implemented exactly in podman, you can set up an alias so that typing docker
causes podman to run.
Installing the podman-docker package sets up such an alias. So every time you run a docker command
line, it actually runs podman for you. More on this package later.
AMD64 and Intel 64 (base and layered images) (no support for the 32-bit AMD and Intel
architecture)
Although not all Red Hat images were supported across all architectures at first, nearly all are now
available on all listed architectures. See Universal Base Images (UBI): Images, repositories, and
packages for a list of supported images.
podman - Client tool for managing containers. Can replace most features of the docker
command for working with individual containers and images.
skopeo - Client tool for copying container images to and from container registries. Includes
features for signing and authenticating images as well.
runc - Container runtime client for running and working with Open Container Initiative (OCI)
format containers.
Using the RHEL subscription model, if you want to create container images, you must properly register
and entitle the host computer on which you build them. When you install packages, as part of the process
of building a container, the build process automatically has access to entitlements available from the
RHEL host. So it can get RPM packages from any repository enabled on that host.
7
Red Hat Enterprise Linux 8 Building, running, and managing containers
1. Install RHEL: If you are ready to begin, you can start by installing a Red Hat Enterprise Linux
system.
2. Register RHEL: Once RHEL is installed, register the system. You will be prompted to enter your
user name and password. Note that the user name and password are the same as your login
credentials for Red Hat Customer Portal.
# subscription-manager register
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: ********
Password: **********
3. Subscribe RHEL: Either auto subscribe or determine the pool ID of a subscription that includes
Red Hat Enterprise Linux. Here is an example of auto-attaching a subscription:
4. Install packages: To start building and working with individual containers, install the container-
tools module, which pulls in the full set of container software packages:
5. Install podman-docker (optional): If you are comfortable with the docker command or use
scripts that call docker directly, you can install the podman-docker package. That package
installs a link that replaces the docker command-line interface with the matching podman
commands instead. It also links the man pages together, so man docker info will show the
podman info man page.
[registries.search]
registries = ['registry.redhat.io', 'registry.access.redhat.com', 'quay.io', 'docker.io']
[registries.insecure]
registries = []
[registries.block]
registries = []
By default, when you use podman search to search for images from a container registries, based on the
registries.conf file, podman looks for the requested image in registry.redhat.io,
registry.access.redhat.com, quay.io, and docker.io, in that order.
To add access to a registry that doesn’t require authentication (an insecure registry), you must add the
name of that registry under the [registries.insecure] section. Any registries that you want to disallow
from access from your local system needs to be added under the [registries.block] section.
8
CHAPTER 1. STARTING WITH CONTAINERS
Here are a few other things you should know about configuring container registries:
If there are multiple registries set for the registries = value, you must separate those registries
by commas.
If the registry uses a non-standard port (i.e., other than TCP ports 443 for secure and 80 for
insecure), you should enter that port number with the registry name. For example:
host.example.com:9999
Registries are searched in the order in which they appear for each section of the registries.conf
file.
If you are a regular user (rootless) running podman and related tools, you can create your own
registries.conf file to override the default settings.
Although container engines, such as Docker, let you run docker commands as a regular (non-root) user,
the docker daemon that carries out those requests runs as root. So, effectively, regular users can make
requests through their containers that harm the system, without there being clarity about who made
those requests. By setting up rootless container users, system administrators limit potentially damaging
container activities from regular users, while still allowing those users to safely run many container
features under their own accounts.
This section describes how to set up your system to use container tools (Podman, Skopeo, and Buildah)
to work with containers as a non-root user (rootless). It also describes some of the limitations you will
encounter because regular user accounts don’t have full access to all operating system features that
their containers might need to run.
1. Install RHEL: Install RHEL 8.1 or upgrade to RHEL 8.1 from RHEL 8.0. Earlier RHEL 7 versions
are missing features needed for this procedure. If you are upgrading from RHEL 7.6 or earlier,
continue to "Upgrade to rootless containers" after this procedure is done.
2. Install podman and slirp4netns: If not already installed, install the podman and slirp4netns
packages:
3. Increase user namespaces: To increase the number of user namespaces in the kernel, type the
following:
9
Red Hat Enterprise Linux 8 Building, running, and managing containers
4. Create a new user account: To create a new user account and add a password for that account
(for example, joe), type the following:
5. Try a podman command: Log in directly as the user you just configured (don’t use su or su - to
become that user because that doesn’t set the correct environment variables) and try to pull
and run an image:
6. Check rootless configuration: To check that your rootless configuration is set up properly, you
can run commands inside the modified user namespace with the podman unshare command.
As the rootless user, the following command lets you see how the uids are assigned to the user
namespace:
Using an existing user name and group name (for example, jill), set the range of accessible user and
group IDs that can be used for their containers. Here are a couple of warnings:
Don’t include the rootless user’s UID and GID in these ranges
If you set multiple rootless container users, use unique ranges for each user
We recommend 65536 UIDs and GIDs for maximum compatibility with existing container
images, but the number can be reduced
Never use UIDs or GIDs under 1000 or reuse UIDs or GIDs from existing user accounts (which,
by default, start at 1000)
Here is an example:
The user/group jill is now allocated 65535 user and group IDs, ranging from 165537-231072.
That user should be able to begin running commands to work with containers now.
10
CHAPTER 1. STARTING WITH CONTAINERS
As a non-root container user, container images are stored under your home directory
($HOME/.local/share/containers/storage/), instead of /var/lib/containers.
Users running rootless containers are given special permission to run as a range of user and
group IDs on the host system. However, they otherwise have no root privileges to the operating
system on the host.
If you need to configure your rootless container environment, edit configuration files in your
home directory ($HOME/.config/containers). Configuration files include storage.conf (for
configuring storage) and libpod.conf (for a variety of container settings). You could also create
a registries.conf file to identify container registries available when you use podman to pull,
search or run images.
A container running as root in a rootless account can turn on privileged features within its own
namespace. But that doesn’t provide any special privileges to access protected features on the
host (beyond having extra UIDs and GIDs). Here are examples of container actions you might
expect to work from a rootless account that will not work:
Anything you want to access from a mounted directory from the host must be accessible by
the UID running your container or your request to access that component will fail.
There are some system features you won’t be able to change without privilege. For
example, you cannot change the system clock by simply setting a SYS_TIME capability
inside a container and running the network time service (ntpd). You would have to run that
container as root, bypassing your rootless container environment and using the root user’s
environment, for that capability to work, such as:
Note that this example allows ntpd to adjust time for the entire system, and not just within
the container.
A rootless container has no ability to access a port less than 1024. Inside the rootless container’s
namespace it can, for example, start a service that exposes port 80 from an httpd service from
the container, but it will not be accessible outside of the namespace:
However, a container would need root privilege, again using the root user’s container
environment, to expose that port to the host system:
The administrator of a workstation can configure it to allow users to expose services below 1024,
but they should understand the security implications. A regular user could, for example, run a
web server on the official port 80 and trick external users into believing that it was configured
by the administrator. This is generally OK on a workstation, but might not be 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:
11
Red Hat Enterprise Linux 8 Building, running, and managing containers
An on-going list of shortcomings of running podman and related tools without root privilege is
contained in Shortcomings of Rootless Podman.
12
CHAPTER 2. WORKING WITH CONTAINER IMAGES
The <registry> is a host that provides a container registry service on TCP <port>. Together, <namespace>
and <name> identify a particular image controlled by <namespace> at that registry. Some registries also
support raw <name>; for those, <namespace> is optional. When it is included, however, the additional
level of hierarchy that <namespace> provides is useful to distinguish between images with the same
<name>. For example:
The registries that Red Hat provides are registry.redhat.io (requiring authentication),
registry.access.redhat.com (requires no authentication), and registry.connect.redhat.com (holds Red
Hat Partner Connect program images). 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. For example:
Use the pull option to pull an image from a remote registry. To pull the rhel base image and rsyslog
logging image from the Red Hat registry, type:
An image is identified by a registry name (registry.redhat.io), a namespace name (ubi8) and the image
name (ubi). You could also add a tag (which defaults to :latest if not entered). The repository name ubi,
when passed to the podman pull command without the name of a registry preceding it, is ambiguous
and could result in the retrieval of an image that originates from an untrusted registry. If there are
multiple versions of the same image, adding a tag, such as latest to form a name such as ubi8/ubi:latest,
lets you choose the image more explicitly.
To see the images that resulted from the above podman pull command, along with any other images on
your system, type podman images:
13
Red Hat Enterprise Linux 8 Building, running, and managing containers
The ubi and rsyslog images are now available on your local system for you to work with.
# podman images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
registry.redhat.io/rhel8/support-tools latest b3d6ce4e0043 2 days ago 234MB
registry.redhat.io/ubi8/ubi-init latest 779a05997856 2 days ago 225MB
registry.redhat.io/ubi8/ubi latest a80dad1c1953 3 days ago 210MB
The podman inspect command displays basic information about what an image does. You also have the
option of mounting the image to your host system and using tools from the host to investigate what’s in
the image. Here is an example of investigating what a container image does before you run it:
1. Inspect an image: Run podman inspect to see what command is executed when you run the
container image, as well as other information. Here are examples of examining the ubi8/ubi and
rhel8/rsyslog container images (with only snippets of information shown here):
14
CHAPTER 2. WORKING WITH CONTAINER IMAGES
The ubi8/ubi container will execute the bash shell, if no other argument is given when you start it
with podman run. If an Entrypoint were set, its value would be used instead of the Cmd value
(and the value of Cmd would be used as an argument to the Entrypoint command).
In the second example, the rhel8/rsyslog container image has built-in install and run labels.
Those labels give an indication of how the container is meant to be set up on the system (install)
and executed (run).
2. Mount a container: Using the podman command, mount an active container to further
investigate its contents. This example runs and lists a running rsyslog container, then displays
the mount point from which you can examine the contents of its file system:
After the podman mount, the contents of the container are accessible from the listed directory
on the host. Use ls to explore the contents of the image.
3. Check the image’s package list: To check the packages installed in the container, tell the rpm
command to examine the packages installed on the container’s mount point:
15
Red Hat Enterprise Linux 8 Building, running, and managing containers
glibc-common-2.17-260.el7.x86_64
nspr-4.19.0-1.el7_5.x86_64
libstdc++-4.8.5-36.el7.x86_64
The following command inspects the ubi8-init image from the Red Hat registry:
NOTE
Another, more intuitive way, to search for images maintained by Red Hat is to search the
Red Hat Container Registry . Included with each image listed in the Red Hat Container
Catalog are descriptions of the image, its contents, health index, and other pertinent
information.
registry.redhat.io
registry.access.redhat.com
quay.io
docker.io
As root user, you can edit the /etc/containers/registries.conf file to change the default, system-wide
16
CHAPTER 2. WORKING WITH CONTAINER IMAGES
search settings. As a regular (rootless) user of podman, you can create your own registries.conf file in
your home directory ($HOME/.config/containers/registries.conf) to override the system-wide
settings.
The following are some podman search command examples. The first example illustrates trying, but
failing, to search all images accessible to you from quay.io. The backslash at the end says to search the
whole registry for all images accessible to you:
Search all available registries for postgresql (resulting in more than 40 images found):
To limit your search for postgresql to images from registry.redhat.io, type the following. Notice that by
entering the registry and the image name, any repository in the registry can be matched:
17
Red Hat Enterprise Linux 8 Building, running, and managing containers
If you want to change your search to use a registry that is not currently set up to search, edit the
[registries.search] section of the /etc/containers/registries.conf file. One reason you might want to do
this is to find a Red Hat partner-supported image (such as crunchy-postgres) instead of a public one
from docker.io or quay.io. To do that, change this:
[registries.search]
registries = ['registry.redhat.io', 'registry.access.redhat.com', 'quay.io', 'docker.io']
To this:
[registries.search]
registries = ['registry.connect.redhat.com']
Instead of choosing from random Crunchy postgres database images, you can see a list of images
supported by an official Red Hat partner.
registryhost/username/NAME:tag
In the previous example, the rhel8 image had an image ID of 474ff279782b. Using podman tag, the
name myrhel8 now also is attached to the image ID. So you could run this container by name (rhel8 or
myrhel8) or by image ID. Notice that without adding a :tag to the name, it was assigned :latest as the tag.
You could have set the tag to 8.0 as follows:
To the beginning of the name, you can optionally add a user name and/or a registry name. The user
name is actually the repository on Docker.io that relates to the user account that owns the repository.
Tagging an image with a registry name was shown in the "Tagging Images" section earlier in this
18
CHAPTER 2. WORKING WITH CONTAINER IMAGES
Above, you can see all the image names assigned to the single image ID.
The myrsyslog.tar file is now stored in your current directory. Later, when you are ready to reuse the
tarball as a container image, you can import it to another podman environment as follows:
Instead of using save and load to store and reload an image, you can make a copy of a container
instead, using podman export and podman import.
If you want to clear out all your images, you could use a command like the following to remove all images
from your local registry (make sure you mean it before you do this!):
19
Red Hat Enterprise Linux 8 Building, running, and managing containers
# podman rmi -a
1ca061b47bd70141d11dcb2272dee0f9ea3f76e9afd71cd121a000f3f5423731
ed904b8f2d5c1b5502dea190977e066b4f76776b98f6d5aa1e389256d5212993
83508706ef1b603e511b1b19afcb5faab565053559942db5d00415fb1ee21e96
To remove images that have multiple names (tags) associated with them, you need to add the force
option to remove them. For example:
# podman rmi -a
A container associated with containers/storage, i.e. via Buildah, CRI-O, etc., may be associated with
this image: 1de7d7b3f531
20
CHAPTER 3. WORKING WITH CONTAINERS
A new process table from inside the container (no processes from the host can be seen).
If you want to make a directory from the host available to the container, map network ports from the
container to the host, limit the amount of memory the container can use, or expand the CPU shares
available to the container, you can do those things from the podman run command line. Here are some
examples of podman run command lines that enable different features.
EXAMPLE #1 (Run a quick command): This podman command runs the cat /etc/os-release command
to see the type of operating system used as the basis for the container. After the container runs the
command, the container exits and is deleted (--rm).
EXAMPLE #2 (View the Dockerfile in the container): This is another example of running a quick
command to inspect the content of a container from the host. All layered images that Red Hat provides
include the Dockerfile from which they are built in /root/buildinfo. In this case you do not need to mount
any volumes from the host.
Now you know what the Dockerfile is called, you can list its contents:
21
Red Hat Enterprise Linux 8 Building, running, and managing containers
RUN INSTALL_PKGS="\
rsyslog \
rsyslog-gnutls \
rsyslog-gssapi \
rsyslog-mysql \
rsyslog-pgsql \
rsyslog-relp \
" && yum -y install $INSTALL_PKGS && rpm -V --nosize
--nofiledigest --nomtime --nomode $INSTALL_PKGS && yum clean all
LABEL com.redhat.component="rsyslog-container"
LABEL name="rhel8/rsyslog"
LABEL version="8.0"
...
EXAMPLE #3 (Run a shell inside the container): Using a container to launch a bash shell lets you look
inside the container and change the contents. This sets the name of the container to mybash. The -i
creates an interactive session and -t opens a terminal session. Without -i, the shell would open and then
exit. Without -t, the shell would stay open, but you wouldn’t be able to type anything to the shell.
Once you run the command, you are presented with a shell prompt and you can start running commands
from inside the container:
Although the container is no longer running once you exit, the container still exists with the new
software package still installed. Use podman ps -a to list the container:
# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
IS INFRA
1ca061b47bd7 .../ubi8/ubi:latest /bin/bash 8 minutes ago Exited 12 seconds ago musing_brown
false
...
You could start that container again using podman start with the -ai options. For example:
EXAMPLE #4 (Bind mounting log files): One way to make log messages from inside a container
available to the host system is to bind mount the host’s /dev/log device inside the container. This
example illustrates how to run an application in a RHEL container that is named log_test that generates
22
CHAPTER 3. WORKING WITH CONTAINERS
log messages (just the logger command in this case) and directs those messages to the /dev/log device
that is mounted in the container from the host. The --rm option removes the container after it runs.
podman ps: The ps option shows all containers that are currently running:
If there are containers that are not running, but were not removed (--rm option), the containers are still
hanging around and can be restarted. The podman ps -a command shows all containers, running or
stopped.
# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES IS
INFRA
d65aecc325a4 ubi8/ubi /bin/bash 3 secs ago Exited (0) 5 secs ago peaceful_hopper false
74b1da000a11 rhel8/rsyslog rsyslog.sh 2 mins ago Up About a minute musing_brown false
23
Red Hat Enterprise Linux 8 Building, running, and managing containers
Status": "running",
Running": true,
...
You can also use inspect to pull out particular pieces of information from a container. The information is
stored in a hierarchy. So to see the container’s IP address (IPAddress under NetworkSettings), use the --
format option and the identity of the container. For example:
Examples of other pieces of information you might want to inspect include .Path (to see the command
run with the container), .Args (arguments to the command), .Config.ExposedPorts (TCP or UDP ports
exposed from the container), .State.Pid (to see the process id of the container) and
.HostConfig.PortBindings (port mapping from container to host). Here’s an example of .State.Pid and
.State.StartedAt:
In the first example, you can see the process ID of the containerized executable on the host system (PID
19593). The ps -ef command confirms that it is the rsyslogd daemon running. The second example
shows the date and time that the container was run.
The reason for using podman exec, instead of just launching the container into a bash shell, is that you
can investigate the container as it is running its intended application. By attaching to the container as it
is performing its intended task, you get a better view of what the container actually does, without
necessarily interrupting the container’s activity.
Here is an example using podman exec to look into a running rsyslog, then look around inside that
container.
1. Launch a container: Launch a container such the rsyslog container image described earlier.
Type podman ps to make sure it is running:
# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
74b1da000a11 rsyslog:latest "/usr/rsyslog.sh 6 minutes ago Up 6 minutes rsyslog
2. Enter the container with podman exec: Use the container ID or name to open a bash shell to
access the running container. Then you can investigate the attributes of the container as
follows:
24
CHAPTER 3. WORKING WITH CONTAINERS
The commands just run from the bash shell (running inside the container) show you several things.
The process table (ps -ef) shows that the /usr/sbin/rsyslogd command is process ID 1.
Processes running in the host’s process table cannot be seen from within the container.
Although the rsyslogd process can be seen on the host process table (it was process ID 19593
on the host).
There is no separate kernel running in the container (uname -r shows the host system’s kernel).
The rpm -qa command lets you see the RPM packages that are included inside the container. In
other words, there is an RPM database inside of the container.
Viewing memory (free -m) shows the available memory on the host (although what the
container can actually use can be limited using cgroups).
If you ran a container, but didn’t remove it (--rm), that container is stored on your local system and ready
25
Red Hat Enterprise Linux 8 Building, running, and managing containers
If you ran a container, but didn’t remove it (--rm), that container is stored on your local system and ready
to run again. To start a previously run container that wasn’t removed, use the start option. To stop a
running container, use the stop option.
To start a container so you can work with it from the local shell, use the -a (attach) and -i (interactive)
options. Once the bash shell starts, run the commands you want inside the container and type exit to kill
the shell and stop the container.
The stop option sends a SIGTERM signal to terminate a running container. If the container doesn’t stop
after a grace period (10 seconds by default), podman sends a SIGKILL signal. You could also use the
podman kill command to kill a container (SIGKILL) or send a different signal to a container. Here’s 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 rm goofy_wozniak
If you want to clear out all your containers, you could use a command like the following to remove all
containers (not images) from your local system (make sure you mean it before you do this!):
26
CHAPTER 3. WORKING WITH CONTAINERS
# podman rm -a
56c496350bd534da7620fe2fa660526a6fc7f1c57b0298291cd2210311fe723b
83ad58c17b20f9e8271171f3023ae094dbfab6ce5708344a68feb121916961ca
a93b696a1f5629300382a8ce860c4ba42f664db98101e82c2dbcc2074b428faf
bee71e61b53bd8b036b2e8cb8f570ef8308403502760a27ee23a4b675d92b93d
27
Red Hat Enterprise Linux 8 Building, running, and managing containers
Supported: Supported by Red Hat for use with your containerized applications. Contains the
same secured, tested, and certified software packages you have in Red Hat Enterprise Linux.
Cataloged: Listed in the Red Hat Container Catalog , where you can find descriptions, technical
details, and a health index for each image.
Updated: Offered with a well-defined update schedule, so you know you are getting the latest
software (see Red Hat Container Image Updates ).
Tracked: Tracked by errata, to help you understand the changes that go into each update.
Reusable: Only need to be downloaded and cached in your production environment once, where
each base image can be reused by all containers that include it as their foundation.
Red Hat Universal Base Images (UBI) for RHEL 8 provide the same quality RHEL software for building
container images as their non-UBI predecessors (rhel6, rhel7, rhel-init, and rhel-minimal base images),
but offer more freedom in how they are used and distributed.
NOTE
For a list of available Red Hat UBI images, and associated information about UBI
repositories and source code, see Universal Base Images (UBI): Images, repositories, and
packages.
For RHEL 8, there are standard, minimal and init base image available. Red Hat also provides a set of
language runtime images, based on Application Streams, that you can build on when you are creating
containers for applications that require specific runtimes. Runtime images include python, php, ruby,
nodejs, and others. All of the RHEL 8 images are UBI images, which means that you can freely obtain
and redistribute them.
There is a set of RHEL 7 images as well that you can run on RHEL 8 systems. For RHEL 7, there are both
UBI (redistributable) and non-UBI (require subscription access and are non-redistributable) base
images. Those images include three regular base images (rhel7, rhel-init, and rhel-minimal) and three
UBI images (ubi7, ubi7-init, and ubi7-minimal).
Although Red Hat does not offer tools for running containers on RHEL 6 systems, it does offer RHEL 6
container images you can use. There are standard (rhel6) and Init (rhel6-init) base image available for
RHEL 6, but no minimal RHEL 6 image. Likewise, there are no RHEL 6 UBI images.
28
CHAPTER 4. USING RED HAT UNIVERSAL BASE IMAGES (STANDARD, MINIMAL, AND RUNTIMES)
Standard RHEL 8 base images (ubi8) have a robust set of software features that include the following:
init system: All the features of the systemd initialization system you need to manage systemd
services 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).
yum: Software needed to install software packages is included via the standard set of yum
commands (yum, yum-config-manager, yumdownloader, and so on). For the UBI base
images, you have access to free yum repositories for adding and updating software.
utilities: The standard base image includes some useful utilities for working inside the container.
Utilities that are in this base image that are not in the minimal images include tar, dmidecode,
gzip, getfacl (and other acl commands), dmsetup (and other device mapper commands), and
others.
RHEL minimal images provide a base for your own container images that is less than half the size of the
standard image, while still being able to draw on RHEL software repositories and maintain any
compliance requirements your software has.
Small size: Minimal images are about 92M on disk and 32M compressed. This makes it less than
half the size of the standard images.
Software installation (microdnf): Instead of including the full-blown yum facility for working
with software repositories and RPM software packages, the minimal images includes the
microdnf utility. Microdnf is a scaled-down version of dnf. It includes only what is needed to
enable and disable repositories, as well as install, remove, and update packages. It also has a
clean option, to clean out cache after packages have been installed.
Based on RHEL packaging: Because minimal images incorporate regular RHEL software RPM
packages, with a few features removed such as extra language files or documentation, you can
continue to rely on RHEL repositories for building your images. This allows you to still maintain
compliance requirements you have that are based on RHEL software. Features of minimal
images make them perfect for trying out applications you want to run with RHEL, while carrying
the smallest possible amount of overhead. What you don’t get with minimal images is an
initialization and service management system (systemd or System V init), a Python run-time
environment, and a bunch of common shell utilities.
Modules for microdnf are not supported: Modules used with the dnf command let you install
multiple versions of the same software, when available. The microdnf utility included with
minimal images does not support modules. So if modules are required, you should use a non-
minimal base images, which include yum.
If your goal, however, is just to try to run some simple binaries or pre-packaged software that doesn’t
have a lot of requirements from the operating system, the minimal images might suit your needs. If your
application does have dependencies on other software from RHEL, you can simply use microdnf to
install the needed packages at build time.
Red Hat intends for you to always use the latest version of the minimal images, which is implied by
29
Red Hat Enterprise Linux 8 Building, running, and managing containers
Red Hat intends for you to always use the latest version of the minimal images, which is implied by
simply requesting ubi8/ubi-minimal or ubi8-minimal. Red Hat does not expect to support older
versions of minimal images going forward.
NOTE
Because the ubi8-init image builds on top of the ubi8 image, their contents are mostly
the same. There are a few critical differences, however. In ubi8-init, the Cmd is set to
/sbin/init, instead of bash, to start the systemd Init service by default. It includes ps and
process related commands (procps-ng package), which ubi8 does not. Also, ubi8-init sets
SIGRTMIN+3 as the StopSignal, as systemd in ubi8-init ignores normal signals to exit
(SIGTERM and SIGKILL), but will terminate if it receives SIGRTMIN+3.
Historically, Red Hat Enterprise Linux base container images were designed for Red Hat customers to
run enterprise applications, but were not free to redistribute. This can create challenges for some
organizations that need to redistribute their applications. That’s where the Red Hat Universal Base
Images come in.
Built from a subset of RHEL content: Red Hat Universal Base images are built from a subset of
normal Red Hat Enterprise Linux content. All of the content used to build selected UBI images is
released in a publicly available set of yum repositories. This lets you install extra packages, as
well as update any package in UBI base images.
Redistributable: The intent of UBI images is to allow Red Hat customers, partners, ISVs, and
others to standardize on one container base image, allowing users to focus on application needs
instead of distribution rules. These images can be shared and run in any environment capable of
running those images. As long as you follow some basic guidelines, you will be able to freely
redistribute your UBI-based images.
Base and runtime images: Besides the three types of base images, UBI versions of various
runtime images are available as well. These runtime images provide a foundation for
applications that can benefit from standard, supported runtimes such as python, php, nodejs,
and ruby.
Enabled yum repositories: The following yum repositories are enabled within each RHEL 8 UBI
image:
The ubi-8-baseos repo holds the redistributable subset of RHEL packages you can include
in your container.
The ubi-8-appstream repo holds Red Hat Software Collections packages that you can add
30
CHAPTER 4. USING RED HAT UNIVERSAL BASE IMAGES (STANDARD, MINIMAL, AND RUNTIMES)
The ubi-8-appstream repo holds Red Hat Software Collections packages that you can add
to a UBI image to help you standardize the environments you use with applications that
require particular runtimes.
Licensing: You are free to use and redistribute UBI images, provided you adhere to the Red Hat
Universal Base Image End User Licensing Agreement.
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 whitelist 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.
Although the legacy RHEL 7 base images will continue to be supported, UBI images are recommended
going forward. For that reason, examples in the rest of this chapter are done with RHEL 8 UBI images.
registry.redhat.io
ubi8-minimal 8.0.0
ubi8-init 8.0.0
registry.redhat.io
ubi-init 8.0.0
ubi-minimal 8.0.0
s2i-core 8.0.0
s2i-base 8.0.0
dotnet-21-runtime 8.0.0
dotnet-21 8.0.0
perl-526 8.0.0
php-72 8.0.0
31
Red Hat Enterprise Linux 8 Building, running, and managing containers
nodejs-10 8.0.0
ruby-25 8.0.0
python-27 8.0.0
python-36 8.0.0
s2i-base 8.0.0
dotnet-21-runtime 8.0.0
dotnet-21 8.0.0
nginx-114 8.0.0
perl-526 8.0.0
php-72 8.0.0
nodejs-10 8.0.0
httpd-24 8.0.0
redis-5 8.0.0
varnish-6 8.0.0
ruby-25 8.0.0
python-27 8.0.0
python-36 8.0.0
memcached 8.0.0
net-snmp 8.0.0
sssd 8.0.0
ipa-server 8.0.0
32
CHAPTER 4. USING RED HAT UNIVERSAL BASE IMAGES (STANDARD, MINIMAL, AND RUNTIMES)
support-tools 8.0.0
rsyslog 8.0.0
GCC 8.0.0
rust-toolset 8.0.0
go-toolset 8.0.0
llvm-toolset 8.0.0
postgresql-10 8.0.0
postgresql-96 8.0.0
mysql-80 8.0.0
mariadb-103 8.0.0
registry.redhat.io
ubi7-minimal 7.6.4
ubi7-init 7.6.4
registry.redhat.io
ubi-init 7.6.4
ubi-minimal 7.6.4
php-72 7.6.4
nodejs-8 7.6.4
ruby-25 7.6.4
python-27 7.6.4
python-36 7.6.4
33
Red Hat Enterprise Linux 8 Building, running, and managing containers
s2i-core 7.6.4
s2i-base 7.6.4
# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.access.redhat.com/ubi8/ubi-minimal latest c94a444803e3 8 hours ago 80.9 MB
registry.access.redhat.com/ubi8/ubi latest 40b488f87628 17 hours ago 214 MB
When pulled in this way, images are available and usable by podman, buildah, skopeo and the CRI-O
container image, but they are not available to the Docker service or docker command. To use these
images with Docker, you can run docker pull instead.
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 can’t 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.
34
CHAPTER 4. USING RED HAT UNIVERSAL BASE IMAGES (STANDARD, MINIMAL, AND RUNTIMES)
Type yum list available to see packages available to add to the image from the UBI yum repos.
(The yum command is not available in the ubi-minimal containers.)
Get source code, as described in the "Getting UBI Container Image Source Code," later in this
chapter.
On systems that include the Docker service, you can use docker run instead.
On ubi images, the yum command is installed to let you draw packages
On ubi-minimal images, the microdnf command (with a smaller feature set) is included instead
of yum.
Keep in mind that installing and working with software packages directly in running containers is just for
adding packages temporarily or learning about the repos. Refer to the “Build a UBI-based image” for
more permanent ways of building UBI-based images.
When you add software to a UBI container, procedures differ for updating UBI images on a subscribed
RHEL host or on an unsubscribed (or non-RHEL) system. Those two ways of working with UBI images
are illustrated below.
With a shell open inside a standard UBI base image container (ubi8/ubi) from a subscribed RHEL host,
run the following command to add a package to that container (for example, the bzip2 package):
To add software inside a standard UBI container that is in the RHEL server repo, but not in UBI repos,
don’t disable any repositories and just install the package:
To install a package that is in a different host repo from inside the standard UBI container, you have to
35
Red Hat Enterprise Linux 8 Building, running, and managing containers
To install a package that is in a different host repo from inside the standard UBI container, you have to
explicitly enable the repo you need. For example:
WARNING
Installing Red Hat packages that are not inside the Red Hat UBI repos might limit
how widely you can distribute the container outside of subscribed hosts.
To install the same package demonstrated earlier (bzip2) from one of those UBI yum repositories on a
subscribed RHEL host from the UBI minimal container, type:
To install packages inside a minimal UBI container from repos available on a subscribed host that are not
part of a UBI yum repo, you would have to explicitly enable those repos. For example:
WARNING
Using non-UBI RHEL repositories to install packages in your UBI images could
restrict your ability to share those images to run outside of subscribed RHEL
systems.
To install that package on an unsubscribed RHEL host from the UBI minimal container, type:
36
CHAPTER 4. USING RED HAT UNIVERSAL BASE IMAGES (STANDARD, MINIMAL, AND RUNTIMES)
As noted earlier, both of these means of adding software to a running UBI container are not intended
for creating permanent UBI-based container images. For that, you should build new layers on to UBI
images, as described in the following section.
Here’s an example of creating a UBI-based Web server container from a Dockerfile with the buildah
utility:
NOTE
1. Create a Dockerfile: Add a Dockerfile with the following contents to a new directory:
FROM registry.access.redhat.com/ubi8/ubi
USER root
LABEL maintainer="John Doe"
# Update image
RUN yum update --disablerepo=* --enablerepo=ubi-8-appstream --enablerepo=ubi-8-baseos
-y && rm -rf /var/cache/yum
RUN yum install --disablerepo=* --enablerepo=ubi-8-appstream --enablerepo=ubi-8-baseos
httpd -y && rm -rf /var/cache/yum
# Add default Web page and expose port
RUN echo "The Web Server is Running" > /var/www/html/index.html
EXPOSE 80
# Start the service
CMD ["-D", "FOREGROUND"]
ENTRYPOINT ["/usr/sbin/httpd"]
2. Build the new image: While in that directory, use buildah to create a new UBI layered image:
37
Red Hat Enterprise Linux 8 Building, running, and managing containers
=============================================================
Installing:
httpd x86_64 2.4.37-10
latest-rhubi-8.0-appstream 1.4 M
Installing dependencies:
apr x86_64 1.6.3-9.el8 latest-rhubi-8.0-appstream 125 k
apr-util x86_64 1.6.1-6.el8 latest-rhubi-8.0-appstream 105 k
httpd-filesystem noarch 2.4.37-10
latest-rhubi-8.0-appstream 34 k
httpd-tools x86_64 2.4.37-10.
...
Transaction Summary
...
Complete!
STEP 6: RUN echo "The Web Server is Running" > /var/www/html/index.html
STEP 7: EXPOSE 80
STEP 8: CMD ["-D", "FOREGROUND"]
STEP 9: ENTRYPOINT ["/usr/sbin/httpd"]
STEP 10: COMMIT
...
Writing manifest to image destination
Storing signatures
--> 36a604cc0dd3657b46f8762d7ef69873f65e16343b54c63096e636c80f0d68c7
So, if you expect to build multiple images that require, for example, php runtime software, you can use
provide a more consistent platform for those images by starting with a PHP software collections image.
Here are a few examples of AppStream container images built on UBI base images, that are available
from the Red Hat Registry (registry.access.redhat.com or registry.redhat.io):
ubi8/nodejs-10: Node.js 10 platform for building and running applications. Used by Node.js 10
Source-To-Image builds
38
CHAPTER 4. USING RED HAT UNIVERSAL BASE IMAGES (STANDARD, MINIMAL, AND RUNTIMES)
ubi8/s2i-core: Base image with essential libraries and tools used as a base for builder images
like perl, python, ruby, and so on
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. Be sure
to use the UBI image names to pull those images.
RHEL 8 AppStream container images are updated every time RHEL 8 base images are updated. For
RHEL 7, these same images (referred to as Red Hat Software Collections images) are updated on a
schedule that is separate from RHEL base image updates (as are related images for Dotnet and
DevTools). Search the Red Hat Container Catalog for details on any of these images. For more
information on update schedules, see Red Hat Container Image Updates .
The source code RPM for each binary RPM package is downloaded to the current directory. Because
the UBI minimal images include a subset of RPMs from the regular UBI images, running the
yumdownloader loop just shown will get you the minimal image packages as well.
Hundreds of RPM packages used in existing Red Hat Software Collections runtime images are
stored in the yum repositories packaged with the new UBI images. Feel free to install those
RPMs on your UBI images to emulate the runtime (python, php, nodejs, etc.) that interests you.
Because some language files and documentation have been stripped out of the minimal UBI
image (ubi8/ubi-minimal), running rpm -Va inside that container will show the contents of
many packages as being missing or modified. If having a complete list of files inside that
container is important to you, consider using a tool such as Tripwire to record the files in the
container and check it later.
After a layered image has been created, use podman history to check which UBI image it was
built on. For example, after completing the webserver example shown earlier, type podman
history johndoe/webserver to see that the image it was built on includes the image ID of the
UBI image you added on the FROM line of the Dockerfile.
39
Red Hat Enterprise Linux 8 Building, running, and managing containers
40
CHAPTER 5. RUNNING SPECIAL CONTAINER IMAGES
Toolbox: Instead of burdening a host system by installing tools needed to debug problems or
monitor features, you can run the toolbox command. Toolbox starts a support-tools container
image that holds tools you can use to run reports or diagnose problems on the host.
Runlabels: Some container images have labels built in that allow you to run those containers
with preset options and arguments. When you do a podman run with a runlabel, the result can
be a prescriptive set of features when you install, run, remove, or upgrade a container image.
Starting up a container from the image, then running a shell inside the container from which you
can access the host system.
Run commands that may not be installed on the host system, such as sosreport, strace, or
tcpdump, in a way that lets them act on the host system.
Install more software inside the container to use on the host system.
Procedure
1. Install the toolbox and podman packages, if you haven’t already. A good way to do that is to
install the full set of container tools:
2. Run the toolbox command to pull and run the support-tools image (inserting your Red Hat
Customer Portal credentials when prompted):
# toolbox
Trying to pull registry.redhat.io/rhel8/support-tools...
...
Would you like to authenticate to registry: 'registry.redhat.io' and try again? [y/N] y
Username: johndoe
Password: *************
Login Succeeded!
Trying to pull registry.redhat.io/rhel8/support-tools...Getting image source signatures
...
Storing signatures
41
Red Hat Enterprise Linux 8 Building, running, and managing containers
30e261462851238d38f4ef2afdaf55f1f8187775c5ca373b43e0f55722faaf97
Spawning a container 'toolbox-root' with image 'registry.redhat.io/rhel8/support-tools'
Detected RUN label in the container image. Using that as the default...
command: podman run -it --name toolbox-root --privileged --ipc=host --net=host --pid=host -e
HOST=/host -e NAME=toolbox-root -e IMAGE=registry.redhat.io/rhel8/support-tools:latest -v
/run:/run -v /var/log:/var/log -v /etc/machine-id:/etc/machine-id -v /etc/localtime:/etc/localtime -
v /:/host registry.redhat.io/rhel8/support-tools:latest
bash-4.4#
A bash shell opens, ready for you to run commands inside the container.
3. From inside the container, the root file system on the host is available from the /host directory.
The other directories shown are all inside the container.
# ls /
bin dev home lib lost+found mnt proc run srv tmp var
boot etc host lib64 media opt root sbin sys usr
4. From inside the container, you can try a command. For example, you can run sosreport to
generate information about your system to send to Red Hat support:
bash-4.4# sosreport
Notice that sosreport is aware that you are in a container. As a result it knows to run on the host
and save the report to the host (/host/var/tmp/sosreport-…).
5. Install a software package inside the container, to add tools that are not already in the container.
For example, to get a core dump of a running process on the host, install the procps and gcore
packages, use ps to get the process ID of a running daemon, then use gcore to get a core
dump:
42
CHAPTER 5. RUNNING SPECIAL CONTAINER IMAGES
Once you type exit, you leave the container and return to the host. You can see that the file
saved to /host/tmp/chronyd.core.809 is available from /tmp/chronyd.core.809 on the host.
At this point, the container is no longer running, but still exists on the system. You can choose to:
Start up the container again: Type toolbox again to restart the container (named toolbox-
root). Any software additions or changes made previously to the container are maintained.
Start with a fresh container: To get rid of the old container, type podman rm toolbox-root.
Then run toolbox again to start with a fresh support-tools container.
Start with different values: You can change the registry, image, or container name used by
toolbox by adding the following values to your host /root/.toolboxrc file:
REGISTRY: Change the registry from which the toolbox image is pulled. For example:
REGISTRY=registry.example.com
TOOLBOX_NAME: Change the name assigned to the running container. For example,
TOOLBOX_NAME=mytoolbox
The next time you run toolbox, the new values from the .toolboxrc file are used.
Privileges: A privileged container (--privileged) runs applications as root user on the host by
default. The container has this ability because it runs with an unconfined_t SELinux security
context. So you would be able to, for example, delete files and directories mounted from the
host that were owned by the root user.
Process tables: Unlike a regular container, that only sees the processes running inside the
container, running a ps -e command within a privileged container (with --pid=host set) lets you
see every process running on the host. So, you can pass a process ID from the host to
commands that run in the privileged container (for example, kill <PID>). With some commands,
however, permissions issues could occur when they try to access processes from the container.
Network interfaces: By default, a container has only one external network interface and one
loopback network interface. With network interfaces open to the host (--net=host), you can
access those network interfaces directly from within the container.
Inter-process communications: The IPC facility on the host is accessible from within the
privileged container. So, you can run commands such as ipcs to see information about active
message queues, shared memory segments, and semaphone sets on the host.
43
Red Hat Enterprise Linux 8 Building, running, and managing containers
Some Red Hat images include labels that provide pre-set command lines for working with those images.
Using the podman container runlabel <label> command, you can tell podman to execute the
command defined in that <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 are done running the container.
Red Hat images that have one or more runlabels include the rsyslog and support-tools images. The
following procedure illustrates how to use those images.
Procedure
2. Display (but do not yet run) the install runlabel for rsyslog:
This shows that the command will open privileges to the host, mount the host root filesystem on
/host in the container, and run an install.sh script.
This creates files on the host system that the rsyslog image will use later.
44
CHAPTER 5. RUNNING SPECIAL CONTAINER IMAGES
This shows that the command opens privileges to the host and mount a bunch of files and
directories from the host inside the container, when it launches the rsyslog container to run the
rsyslogd daemon.
The rsyslog container opens privileges, mounts what it needs from the host, and runs the
rsyslogd daemon in the background (-d). The rsyslogd daemon begins gathering log messages
and directing messages to files in the /var/log directory.
In this case, the uninstall.sh script just removes the /etc/logrotate.d/syslog file. Note that it
doesn’t clean up the configuration files.
Procedure
45
Red Hat Enterprise Linux 8 Building, running, and managing containers
2. Display (but do not yet run) the run runlabel for support-tools:
This shows that the command mounts directories and opens privileges and namespaces (ipc,
net, and pid) to the host system. It assigns the host’s root file system to the /host directory in
the container.
You can now run reports or debug tools against the host system (/host). When you are done, type exit
to exit the shell and stop the container.
46
CHAPTER 6. BUILDING CONTAINER IMAGES WITH BUILDAH
This section describes how to use the buildah command to create and otherwise work with containers
and container images.
No Daemon!: Bypasses the Docker daemon! So no container runtime (Docker, CRI-O, or other)
is needed to use Buildah.
Base image or scratch: Lets you not only build an image based on another container, but also
lets you start with an empty image (scratch).
Build tools external: Doesn’t include build tools within the image itself. As a result, Buildah:
Makes the image more secure by not having the software used to build the container (like
gcc, make, and dnf) within the resulting image.
Creates images that require fewer resources to transport the images (because they are
smaller).
Buildah is able to operate without Docker or other container runtimes by storing data separately and by
including features that let you not only build images, but run those images as containers as well. By
default, Buildah stores images in an area identified as containers-storage (/var/lib/containers).
NOTE
The containers-storage location that the buildah command uses by default is the same
place that the CRI-O container engine uses for storing local copies of images. So images
pulled from a registry by either CRI-O or Buildah, or committed by the buildah command,
will be stored in the same directory structure. Currently, however, CRI-O and Buildah
cannot share containers, though they can share images.
There are more than a dozen options to use with the buildah command. Some of the main activities you
can do with the buildah command include:
Build a container from a Dockerfile: Use a Dockerfile to build a new container image ( buildah
bud).
Build a container from another image or scratch: Build a new container, starting with an
existing base image (buildah from <imagename>) or from scratch ( buildah from scratch)
Inspecting a container or image: View metadata associated with the container or image
(buildah inspect)
Mount a container: Mount a container’s root filesystem to add or change content ( buildah
mount).
47
Red Hat Enterprise Linux 8 Building, running, and managing containers
Create a new container layer: Use the updated contents of a container’s root filesystem as a
filesystem layer to commit content to a new image (buildah commit).
For more details on Buildah, see the GitHub Buildah page . The GitHub Buildah site includes man pages
and software that might be more recent than is available with the RHEL version. Here are some other
articles on Buildah that might interest you:
With the buildah package installed, you can refer to the man pages included with the buildah package
for details on how to use it. To see the available man pages and other documentation, then open a man
page, type:
NAME
Buildah - A command line tool that facilitates building OCI container images.
...
The following sections describe how to use buildah to get containers, build a container from a
Dockerfile, build one from scratch, and manage containers in various ways.
48
CHAPTER 6. BUILDING CONTAINER IMAGES WITH BUILDAH
# buildah containers
CONTAINER ID BUILDER IMAGE ID IMAGE NAME CONTAINER NAME
c6c9279ecc0f * 3da40a1670b5 ...ubi8/ubi:latest ubi-working-container
Notice that the result of the buildah from command is an image (registry.redhat.io/ubi8/ubi:latest) and
a working container that is ready to run from that image (ubi-working-container). Here’s an example of
how to execute a command from that container:
The image and container are now ready for use with Buildah.
This simple example starts with two files in the current directory: Dockerfile (which holds the instructions
for building the container image) and myecho (a script that echoes a few words to the screen):
# ls
Dockerfile myecho
# cat Dockerfile
FROM registry.redhat.io/ubi8/ubi
ADD myecho /usr/local/bin
ENTRYPOINT "/usr/local/bin/myecho"
# cat myecho
echo "This container works!"
# chmod 755 myecho
# ./myecho
This container works!
With the Dockerfile in the current directory, build the new container as follows:
The buildah bud command creates a new image named myecho. To run see that new image, type:
# buildah images
IMAGE NAME IMAGE TAG IMAGE ID CREATED AT SIZE
localhost/myecho latest a3882af49784 Jun 21, 2019 12:21 216 MB
49
Red Hat Enterprise Linux 8 Building, running, and managing containers
"Entrypoint": [
"/usr/local/bin/myecho"
],
"WorkingDir": "/",
"Labels": {
"architecture": "x86_64",
"authoritative-source-url": "registry.access.redhat.com",
"build-date": "2018-09-19T20:46:28.459833",
Note that the container output has added information, such as the container name, container id, process
label, and mount label to what was in the image.
Once you have modified the container, use buildah commit to commit the changes to a new image.
50
CHAPTER 6. BUILDING CONTAINER IMAGES WITH BUILDAH
After getting an image with buildah from, you can use that image as the basis for a new image. The
following text shows how to create a new image by mounting a working container, adding files to that
container, then committing the changes to a new image.
Type the following to view the working container you used earlier:
# buildah containers
CONTAINER ID BUILDER IMAGE ID IMAGE NAME CONTAINER NAME
Mount the container image and set the mount point to a variable ($mymount) to make it easier to deal
with:
To commit the content you added to create a new image (named myecho), type the following:
To check that the new image includes your changes, create a working container and run it:
# buildah images
IMAGE ID IMAGE NAME CREATED AT SIZE
a7e06d3cd0e2 docker.io/library/myecho2:latest
Oct 12, 2017 15:15 3.144 KB
# buildah from docker.io/library/myecho2:latest
myecho2-working-container
# buildah run myecho2-working-container
This container works!
We even modified it.
You can see that the new echo command added to the script displays the additional text.
With buildah copy, you can copy files to a container without mounting it first. Here’s an example, using
51
Red Hat Enterprise Linux 8 Building, running, and managing containers
With buildah copy, you can copy files to a container without mounting it first. Here’s an example, using
the myecho-working-container created (and unmounted) in the previous section, to copy a new script
to the container and change the container’s configuration to run that script by default.
# cat newecho
echo "I changed this container"
# chmod 755 newecho
Change the configuration to use the newecho script as the new entrypoint:
Run the new container, which should result in the newecho command being executed:
If the container behaved as you expected it would, you could then commit it to a new image
(mynewecho):
With a scratch container, you can simply copy executables that have no dependencies to the
scratch image and make a few configuration settings to get a minimal container to work.
To use tools like yum or rpm packages to populate the scratch container, you need to at least
initialize an RPM database in the container and add a release package. The example below
shows how to do that.
If you end up adding a lot of RPM packages, consider using the rhel or rhel-minimal base
images instead of a scratch image. Those base images have had documentation, language
packs, and other components trimmed out, which can ultimately result in your image being
smaller.
This example adds a Web service (httpd) to a container and configures it to run. In the example, instead
52
CHAPTER 6. BUILDING CONTAINER IMAGES WITH BUILDAH
This creates just an empty container (no image) that you can mount as follows:
Initialize an RPM database within the scratch image and add the redhat-release package (which includes
other files needed for RPMs to work):
Add some text to an index.html file in the container, so you will be able to test it later:
Instead of running httpd as an init service, set a few buildah config options to run the httpd daemon
directly from the container:
By default, the buildah commit command adds the docker.io repository name to the image name and
copies the image to the storage area for your local Docker service (/var/lib/docker). For now, you can
use the Image ID to run the new image as a container with the docker command:
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/myhttpd latest 47c0795d7b0e 9 minutes ago 665.6 MB
# docker run -p 8080:80 -d --name httpd-server 47c0795d7b0e
# curl localhost:8080
Your httpd container from scratch worked.
53
Red Hat Enterprise Linux 8 Building, running, and managing containers
When you are done with particular containers or images, you can remove them with buildah rm or
buildah rmi, respectively. Here are some examples.
To remove the container created in the previous section, you could type the following to see the
mounted container, unmount it and remove it:
# buildah containers
CONTAINER ID BUILDER IMAGE ID IMAGE NAME CONTAINER NAME
05387e29ab93 * c37e14066ac7 docker.io/library/myecho:latest myecho-working-container
# buildah mount
05387e29ab93 /var/lib/containers/storage/devicemapper/mnt/9274181773a.../rootfs
# buildah umount 05387e29ab93
# buildah rm 05387e29ab93
05387e29ab93151cf52e9c85c573f3e8ab64af1592b1ff9315db8a10a77d7c22
To remove the image you created previously, you could type the following:
Push containers to and pull them from a private registry with buildah.
Push and pull container between your local system and the Docker Registry.
Use credentials to associate your containers with a registry account when you push them.
Use the skopeo command, in tandem with the buildah command, to query registries for information
about container images.
Set up a private registry (OpenShift provides a container registry or you can set up a Red Hat
Quay container registry).
To push an image from your local Buildah container storage, check the image name, then push it using
the buildah push command. Remember to identify both the local image name and a new name that
includes the location. For example, a registry running on the local system that is listening on TCP port
5000 would be identified as localhost:5000.
# buildah images
IMAGE ID IMAGE NAME CREATED AT SIZE
54
CHAPTER 6. BUILDING CONTAINER IMAGES WITH BUILDAH
Use the curl command to list the images in the registry and skopeo to inspect metadata about the
image:
# curl http://localhost:5000/v2/_catalog
{"repositories":["myatomic","myecho2"]}
# curl http://localhost:5000/v2/myecho2/tags/list
{"name":"myecho2","tags":["latest"]}
# skopeo inspect --tls-verify=false docker://localhost:5000/myecho2:latest | less
{
"Name": "localhost:5000/myecho2",
"Digest": "sha256:8999ff6050...",
"RepoTags": [
"latest"
],
"Created": "2017-11-21T16:50:25.830343Z",
"DockerVersion": "",
"Labels": {
"architecture": "x86_64",
"authoritative-source-url": "registry.redhat.io",
At this point, any tool that can pull container images from a container registry can get a copy of your
pushed image. For example, on a RHEL 7 system you could start the docker daemon and try to pull the
image so it can be used by the docker command as follows:
As with the private registry, you can then get and run the container from the Docker Hub with the
podman, buildah or docker command:
55
Red Hat Enterprise Linux 8 Building, running, and managing containers
myecho2-working-container-2
# podman run myecho2-working-container-2
This container works!
56
CHAPTER 7. RUNNING CONTAINERS AS SYSTEMD SERVICES WITH PODMAN
Red Hat has become a leader in integrating containers with systemd, so that OCI and Docker-formatted
containers built by Podman can be managed in the same way that other services and features are
managed in a Linux system. This chapter describes how you can use the systemd initialization service to
work with containers in two different ways:
Starting Containers with systemd: By setting up a systemd unit file on your host computer, you
can have the host automatically start, stop, check the status, and otherwise manage a container
as a systemd service.
Starting services within a container using systemd: Many Linux services (Web servers, file
servers, database servers, and so on) are already packaged for Red Hat Enterprise Linux to run
as systemd services. If you are using the latest RHEL container image, you can set the RHEL
container image to start the systemd service, then automatically start selected services within
the container when the container starts up.
The following two sections describe how to use systemd container in those ways.
This section provides an example of a container that is configured to run directly on a RHEL system as a
systemd service.
1. Get the image you want to run on your system. For example, to use the redis service from
docker.io, run the following command:
2. Run the image as a container, giving it a name you want to use in the systemd service file. For
example, to name the running redis container redis_server, type the following:
3. Configure the container as a systemd service by creating the unit configuration file in the
/etc/systemd/system/ directory. For example, the contents of the /etc/systemd/system/redis-
container.service can look as follows (note that redis_server matches the name you set on the
podman run line):
[Unit]
Description=Redis container
[Service]
57
Red Hat Enterprise Linux 8 Building, running, and managing containers
Restart=always
ExecStart=/usr/bin/podman start -a redis_server
ExecStop=/usr/bin/podman stop -t 2 redis_server
[Install]
WantedBy=local.target
4. After creating the unit file, to start the container automatically at boot time, type the following:
5. Once the service is enabled, it will start at boot time. To start it immediately and check the
status of the service, type the following:
To learn more about configuring services with systemd, refer to the System Administrator’s Guide
chapter called Managing Services with systemd.
Start the /sbin/init process (the systemd service) to run as PID 1 within the container.
Start all systemd services that are installed and enabled within the container, in order of
dependencies.
Allow systemd to restart services or kill zombie processes for services started within the
container.
The general steps for building a container that is ready to be used as a systemd services is:
Install the package containing the systemd-enabled service inside the container. This can
include dozens of services that come with RHEL, such as Apache Web Server (httpd), FTP
server (vsftpd), Proxy server (squid), and many others. For this example, we simply install an
Apache (httpd) Web server.
Use the systemctl command to enable the service inside the container.
Add data for the service to use in the container (in this example, we add a Web server test
58
CHAPTER 7. RUNNING CONTAINERS AS SYSTEMD SERVICES WITH PODMAN
Add data for the service to use in the container (in this example, we add a Web server test
page). For a real deployment, you would probably connect to outside storage.
In this example, we build a container by creating a Dockerfile 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.
1. Create Dockerfile: In a separate directory, create a file named Dockerfile with the following
contents:
FROM registry.access.redhat.com/ubi8/ubi-init
RUN yum -y install httpd; yum clean all; systemctl enable httpd;
RUN echo "Successful Web Server Test" > /var/www/html/index.html
RUN mkdir /etc/systemd/system/httpd.service.d/; echo -e '[Service]\nRestart=always' >
/etc/systemd/system/httpd.service.d/httpd.conf
EXPOSE 80
The Dockerfile installs the httpd package, enables the httpd service to start at boot time (i.e.
when the container starts), creates a test file (index.html), exposes the Web server to the host
(port 80), and starts the systemd init service (/sbin/init) when the container starts.
2. Build the container: From the directory containing the Dockerfile, type the following:
3. Open Selinux permission. If SELinux is enabled on your system, you must turn on the
container_manage_cgroup boolean to run containers with systemd as shown here (see the
Containers running systemd solution for details):
# setsebool -P container_manage_cgroup 1
4. Run the container: Once the container is built and named mysysd, type the following to run the
container:
From this command, the mysysd image runs as the mysysd_run container as a daemon process,
with port 80 from the container exposed to port 80 on the host system.
5. Check that the container is running: To make sure that the container is running and that the
service is working, type the following commands:
At this point, you have a container that starts up a Web server as a systemd service inside the container.
Install and run any services you like in this same way by modifying the Dockerfile and configuring data
and opening ports as appropriate.
59
Red Hat Enterprise Linux 8 Building, running, and managing containers
8.1. PODMAN
The podman command (which stands for Pod Manager) lets you run containers as standalone entities,
without requiring that Kubernetes, the Docker runtime, or any other container runtime be involved. It is a
tool that can act as a replacement for the docker command, implementing the same command-line
syntax, while it adds even more container management features. The podman features include:
Based on docker interface: Because podman syntax mirrors the docker command,
transitioning to podman should be easy for those familiar with docker.
Managing containers and images: Both Docker- and OCI-compatible container images can be
used with podman to:
Create and manage container images (push, commit, configure, build, and so on)
Managing pods: Besides running individual containers, podman can run a set of containers
grouped in a pod. A pod is the smallest container unit that Kubernetes manages.
Working with no runtime: No runtime environment is used by podman to work with containers.
Here are a few implementation features of podman you should know about:
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, however. Eventually those features
will be able to share containers.
The podman command, like the docker command, can build container images from a
Dockerfile.
The podman command can be a useful troubleshooting tool when the CRI-O service is
unavailable.
Options to the docker command that are not supported by podman include network, node,
plugin (podman does not support plugins), rename (use rm and create to rename containers
with podman), secret, service, stack, and swarm ( podman does not support Docker Swarm).
The container and image options are used to run subcommands that are used directly in
podman.
To interact programmatically with podman, a remote API for Podman is available using a
technology called varlink. This will let podman listen for API requests from remote tools (such
as the RHEL 8 web console or the atomic command) and respond to them.
60
CHAPTER 8. CONTAINER COMMAND-LINE REFERENCE
61
Red Hat Enterprise Linux 8 Building, running, and managing containers
# podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.redhat.io/ubi8/ubi latest de9c26f23799 5 weeks ago 80.1MB
registry.redhat.io/ubi8/ubi latest fd1ba0b398a8 5 weeks ago 211MB
62
CHAPTER 8. CONTAINER COMMAND-LINE REFERENCE
[
{
"Id": "4bbd153adf8487a8a5114af0d6...",
"Digest": "sha256:9999e735605c73f...",
"RepoTags": [
"registry.access.redhat.com/ubi8/ubi:latest"
],
"RepoDigests": [
"registry.access.redhat.com/ubi8/ubi/rhel@sha256:9999e7356...
# podman ps -a
CONTAINER ID IMAGE COMMAND
CREATED AT STATUS PORTS NAMES
440becd26893 registry.redhat.io/ubi8/ubi-minimal:latest /bin/bash
2018-05-10 09:02:52 -0400 EDT Exited (0) About an hour ago happy_hodgkin
8414218c04f9 registry.redhat.io/ubi8/ubi:latest /bin/bash
2018-05-10 09:48:07 -0400 EDT Exited (0) 14 minutes ago nostalgic_boyd
# podman rm 440becd26893
1. Start a containerized service that runs as a daemon process (mariadb, in this example):
63
Red Hat Enterprise Linux 8 Building, running, and managing containers
# podman ps
CONTAINER ID IMAGE
COMMAND CREATED STATUS
PORTS NAMES
e421a3424ab0 registry.access.redhat.com/rhscl/mariadb-102-rhel7:latest
container-entrypo... 19 seconds ago Up 16 seconds ago
0.0.0.0:3306->3306/tcp mymariadb
3. Use the container name or ID to generate the Kubernetes yaml and direct it into a file:
Note that this tool does not handle volumes and PVs.
4. You can now use the yaml file to create a pod in your Kubernetes or OpenShift environment:
64
CHAPTER 8. CONTAINER COMMAND-LINE REFERENCE
# cat Dockerfile
FROM registry.redhat.io/ubi8/ubi
ENTRYPOINT "echo 'Podman built this container.'"
8.2. RUNC
"runC" is a lightweight, portable implementation of the Open Container Initiative (OCI) container
runtime specification. runC unites a lot of the low-level features that make running containers possible.
It shares a lot of low-level code with Docker but it is not dependent on any of the components of the
Docker platform.
runc supports Linux namespaces, live migration, and has portable performance profiles. It also provides
full support for Linux security features such as SELinux, control groups (cgroups), seccomp, and others.
You can build and run images with runc, or you can run OCI-compatible images with runc.
$ runc spec
This command creates a config.json file that only contains a bare-bones structure that you will need to
edit. Most importantly, you will need to change the "args" parameter to identify the executable to run.
By default, "args" is set to "sh".
"args": [
"sh"
],
As an example, you can download the Red Hat Enterprise Linux base image (ubi8/ubi) using podman
then export it, create a new bundle for it with runc, and edit the "config.json" file to point to that image.
You can then create the container image and run an instance of that image with runc. Use the following
commands:
65
Red Hat Enterprise Linux 8 Building, running, and managing containers
In this example, the name of the container instance is "rhel-container". Running that container, by
default, starts a shell, so you can begin looking around and running commands from inside that container.
Type exit when you are done.
The name of a container instance must be unique on the host. To start a new instance of a container:
You can provide the bundle directory using the "-b" option. By default, the value for the bundle is the
current directory.
You will need root privileges to start containers with runc. To see all commands available to runc and
their usage, run "runc --help".
8.3. SKOPEO
With the skopeo command, you can work with container images from registries without using the docker
daemon or the docker command. Registries can include the Docker Registry, your own local registries,
Red Hat Quay or OpenShift registries. Activities you can do with skopeo include:
inspect: The output of a skopeo inspect command is similar to what you see from a docker
inspect command: low-level information about the container image. That output can be in json
format (default) or raw format (using the --raw option).
copy: With skopeo copy you can copy a container image from a registry to another registry or
to a local directory.
layers: The skopeo layers command lets you download the layers associated with images so
that they are stored as tarballs and associated manifest files in a local directory.
Like the buildah command and other tools that rely on the containers/image library, the skopeo
command can work with images from container storage areas other than those associated with Docker.
Available transports to other types of container storage include: containers-storage (for images stored
by buildah and CRI-O), ostree (for atomic and system containers), oci (for content stored in an OCI-
compliant directory), and others. See the skopeo man page for details.
To try out skopeo, you could set up a local registry, then run the commands that follow to inspect, copy,
and download image layers. If you want to follow along with the examples, start by doing the following:
Install a local registry (such as Red Hat Quay . Container registry software available in the
docker-distribution package for RHEL 7, is not available for RHEL 8.
Pull the latest RHEL image to your local system (podman pull ubi8/ubi).
Retag the RHEL image and push it to your local registry as follows:
66
CHAPTER 8. CONTAINER COMMAND-LINE REFERENCE
The rest of this section describes how to inspect, copy and get layers from the RHEL image.
NOTE
The skopeo tool by default requires a TLS connection. It fails when trying to use an
unencrypted connection. To override the default and use an http registry, prepend http:
to the <registry>/<image> string.
The following example inspects the mariadb container image from the Docker Registry:
Assuming you pushed a container image tagged localhost/myubi8 to a container registry running on
your local system, the following command inspects that image:
67
Red Hat Enterprise Linux 8 Building, running, and managing containers
"BZComponent": "rhel-server-docker",
"Build_Host": "rcm-img01.build.eng.bos.redhat.com",
"Name": "myubi8",
"Release": "75",
"Vendor": "Red Hat, Inc.",
"Version": "8.0"
},
"Architecture": "amd64",
"Os": "linux",
"Layers": [
"sha256:16dc1f96e3a1bb628be2e00518fec2bb97bd5933859de592a00e2eb7774b6ecf"
]
}
The result of the skopeo copy command is a tarball (16d*.tar) and a manifest.json file representing the
image being copied to the directory you identified. If there were multiple layers, there would be multiple
tarballs. The skopeo copy command can also copy images to another registry. If you need to provide a
signature to write to the destination registry, you can do that by adding a --sign-by= option to the
command line, followed by the required key-id.
As you can see from this example, a new directory is created (layers-myubi8-latest-698503105) and, in
this case, a single layer tarball and a manifest.json file are copied to that directory.
68
CHAPTER 9. ADDITIONAL RESOURCES
69