Chapter 1. Starting with containers
Linux containers have emerged as a key open source application packaging and delivery technology, combining lightweight application isolation with the flexibility of image-based deployment methods. RHEL implements Linux containers using core technologies such as:
- Control groups (cgroups) for resource management
- Namespaces for process isolation
- SELinux for security
- Secure multi-tenancy
These technologies reduce the potential for security exploits and provides you with an environment for producing and running enterprise-quality containers.
Red Hat OpenShift provides powerful command-line and Web UI tools for building, managing, and running containers in units referred to as pods. Red Hat allows you to build and manage individual containers and container images outside of OpenShift. This guide describes the tools provided to perform those tasks that run directly on RHEL systems.
Unlike other container tools implementations, the tools described here do not center around the monolithic Docker container engine and
docker command. Instead, Red Hat provides a set of command-line tools that can operate without a container engine. These include:
podman - for directly managing pods and container images (
exec, and so on)
- buildah - for building, pushing, and signing container images
- skopeo - for copying, inspecting, deleting, and signing images
- runc - for providing container run and build features to podman and buildah
- crun - an optional runtime that can be configured and gives greater flexibility, control, and security for rootless containers
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.
1.1. Running containers without Docker
Red Hat removed the Docker container engine and the docker command from RHEL 8.
- Docker is not supported in RHEL 8.
The Podman, Skopeo, and Buildah tools were developed to replace Docker command features. Each tool in this scenario is more lightweight and focused on a subset of features.
The main advantages of Podman, Skopeo and Buildah tools include:
- Running in rootless mode - rootless containers are much more secure, as they run without any added privileges
- No daemon required - these tools have much lower resource requirements at idle, since when you are not running containers, Podman is not running versus having a daemon always running
- Native systemd integration - Podman allows you to create systemd unit files and run containers as system services
If you still want to use Docker in RHEL, you can get Docker from different upstream projects, but it is unsupported in RHEL 8. Because so many Docker command-line features have been implemented in Podman, you can set up an alias so that typing
podman to run.
podman-docker package sets up this alias. As a result, every time you run a
docker command, it actually runs
Podman also supports the Docker Socket API, so the
podman-docker package also sets up a link between
/var/run/podman/podman.sock. As a result, you can continue to run your Docker API commands with
docker-compose tools without requiring the Docker daemon. Podman will service the requests.
1.2. Choosing a RHEL architecture for containers
Red Hat provides container images and container-related software for the following computer architectures:
- AMD64 and Intel 64 (base and layered images; no support for 32-bit architectures)
- PowerPC 8 and 9 64-bit (base image and most layered images)
- 64-bit IBM Z (base image and most layered images)
- ARM 64-bit (base image only)
Although not all Red Hat images were supported across all architectures at first, nearly all are now available on all listed architectures.
1.3. Getting container tools
This procedure shows how you can install the
container-tools module which contains the Podman, Buildah, Skopeo, and runc tools.
- Install RHEL.
Register RHEL: Enter your user name and password. The user name and password are the same as your login credentials for Red Hat Customer Portal:
# subscription-manager register Registering to: subscription.rhsm.redhat.com:443/subscription Username: ******** Password: **********
Subscribe to RHEL.
To auto-subscribe to RHEL:
# subscription-manager attach --auto
To subscribe to RHEL by Pool ID:
# subscription-manager attach --pool PoolID
# yum module install -y container-tools
Optional: Install the
# yum install -y podman-docker
podman-dockerpackage replaces the Docker command-line interface and
docker-apiwith the matching Podman commands instead.
1.4. Setting up rootless containers
Running the container tools such as Podman, Skopeo, or Buildah as a user with superuser privileges (root user) is the best way to ensure that your containers have full access to any feature available on your system. However, with the feature called "Rootless Containers" generally available as of RHEL 8.1, you can work with containers as a regular user.
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. As a result, regular users can make requests through their containers that can harm the system. By setting up rootless container users, system administrators prevent potentially damaging container activities from regular users, while still allowing those users to safely run most container features under their own accounts.
This procedure describes how to set up your system to use Podman, Skopeo, and Buildah tools to work with containers as a non-root user (rootless). It also describes some of the limitations you will encounter, because regular user accounts do not have full access to all operating system features that their containers might need to run.
- You need to become a root user to set up your RHEL system to allow non-root user accounts to use container tools.
- Install RHEL.
# yum install podman -y
Create a new user account:
# useradd -c "Joe Jones" joe # passwd joe
The user is automatically configured to be able to use rootless Podman. The
useraddcommand automatically sets the range of accessible user and group IDs automatically in the
Connect to the user:
$ ssh email@example.com
Do not use
su - commands because these commands do not set the correct environment variables.
$ podman pull registry.access.redhat.com/ubi8/ubi
Run the container named
myubiand display the OS version:
$ podman run --rm --name=myubi registry.access.redhat.com/ubi8/ubi cat \ /etc/os-release NAME="Red Hat Enterprise Linux" VERSION="8.4 (Ootpa)"
1.5. Upgrading to rootless containers
This section shows how to upgrade to rootless containers from RHEL 7. You must configure user and group IDs manually.
Here are some things to consider when upgrading to rootless containers from RHEL 7:
- If you set up multiple rootless container users, use unique ranges for each user.
- Use 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).
- The user account has been created.
usermodcommand to assign UIDs and GIDs to a user:
# usermod --add-subuids 200000-201000 --add-subgids 200000-201000 username
usermod --add-subuidcommand manually adds a range of accessible user IDs to the user’s account.
usermod --add-subgidscommand manually adds a range of accessible user GIDs and group IDs to the user’s account.
Optional: Check that the UIDs and GIDs are set properly:
# grep username /etc/subuid /etc/subgid #/etc/subuid:username:200000:1001 #/etc/subgid:username:200000:1001
1.6. Special considerations for rootless containers
There are several considerations when running containers as a non-root user:
The path to the host container storage is different for root users (
/var/lib/containers/storage) and non-root users (
- Users running rootless containers are given special permission to run as a range of user and group IDs on the host system. However, they have no root privileges to the operating system on the host.
If you need to configure your rootless container environment, create configuration files in your home directory (
$HOME/.config/containers). Configuration files include
storage.conf(for configuring storage) and
containers.conf(for a variety of container settings). You could also create a
registries.conffile to identify container registries that are available when you use Podman to pull, search, or run images.
There are some system features you cannot change without root privileges. For example, you cannot change the system clock by setting a
SYS_TIMEcapability inside a container and running the network time service (
ntpd). You have to run that container as root, bypassing your rootless container environment and using the root user’s environment. For example:
$ sudo podman run -d --cap-add SYS_TIME ntpd
Note that this example allows
ntpdto adjust time for the entire system, and not just within the container.
A rootless container cannot access a port numbered less than 1024. Inside the rootless container namespace it can, for example, start a service that exposes port 80 from an httpd service from the container, but it is not accessible outside of the namespace:
$ podman run -d httpd
However, a container would need root privileges, using the root user’s container environment, to expose that port to the host system:
$ sudo podman run -d -p 80:80 httpd
The administrator of a workstation can allow users to expose services on ports numbered lower than 1024, but they should understand the security implications. A regular user could, for example, run a web server on the official port 80 and make external users believe that it was configured by the administrator. This is acceptable on a workstation for testing, but might not be a good idea on a network-accessible development server, and definitely should not be done on production servers. To allow users to bind to ports down to port 80 run the following command:
# echo 80 > /proc/sys/net/ipv4/ip_unprivileged_port_start