Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 17. Running Skopeo, Buildah, and Podman in a container
You can run Skopeo, Buildah, and Podman in a container.
With Skopeo, you can inspect images on a remote registry without having to download the entire image with all its layers. You can also use Skopeo for copying images, signing images, syncing images, and converting images across different formats and layer compressions.
Buildah facilitates building OCI container images. With Buildah, you can create a working container, either from scratch or using an image as a starting point. You can create an image either from a working container or using the instructions in a Containerfile. You can mount and unmount a working container’s root filesystem.
With Podman, you can manage containers and images, volumes mounted into those containers, and pods made from groups of containers. Podman is based on a libpod library for container lifecycle management. The libpod library provides APIs for managing containers, pods, container images, and volumes.
Reasons to run Buildah, Skopeo, and Podman in a container:
CI/CD system:
- Podman and Skopeo: You can run a CI/CD system inside of Kubernetes or use OpenShift to build your container images, and possibly distribute those images across different container registries. To integrate Skopeo into a Kubernetes workflow, you need to run it in a container.
-
Buildah: You want to build OCI/container images within a Kubernetes or OpenShift CI/CD systems that are constantly building images. Previously, people used a Docker socket to connect to the container engine and perform a
docker buildcommand. This was the equivalent of giving root access to the system without requiring a password which is not secure. For this reason, Red Hat recommends using Buildah in a container.
Different versions:
- All: You are running an older operating system on the host but you want to run the latest version of Skopeo, Buildah, or Podman. The solution is to run the container tools in a container. For example, this is useful for running the latest version of the container tools provided in Red Hat Enterprise Linux 8 on a Red Hat Enterprise Linux 7 container host which does not have access to the newest versions natively.
HPC environment:
- All: A common restriction in HPC environments is that non-root users are not allowed to install packages on the host. When you run Skopeo, Buildah, or Podman in a container, you can perform these specific tasks as a non-root user.
17.1. Running Skopeo in a container Link kopierenLink in die Zwischenablage kopiert!
You can inspect a remote container image using Skopeo. Running Skopeo in a container means that the container root filesystem is isolated from the host root filesystem. To share or copy files between the host and container, you have to mount files and directories.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Log in to the registry.redhat.io registry:
podman login registry.redhat.io
$ podman login registry.redhat.io Username: myuser@mycompany.com Password: <password> Login Succeeded!Copy to Clipboard Copied! Toggle word wrap Toggle overflow Get the
registry.redhat.io/rhel10/skopeocontainer image:podman pull registry.redhat.io/rhel10/skopeo
$ podman pull registry.redhat.io/rhel10/skopeoCopy to Clipboard Copied! Toggle word wrap Toggle overflow Inspect a remote container image
registry.access.redhat.com/ubi10/ubiusing Skopeo:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The
--rmoption removes theregistry.redhat.io/rhel10/skopeoimage after the container exits.
17.2. Running Skopeo in a container using credentials Link kopierenLink in die Zwischenablage kopiert!
Working with container registries requires an authentication to access and alter data. Skopeo supports various ways to specify credentials.
With this approach you can specify credentials on the command line using the --cred USERNAME[:PASSWORD] option.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Inspect a remote container image using Skopeo against a locked registry:
podman run --rm registry.redhat.io/rhel10/skopeo inspect --creds $USER:$PASSWORD docker://$IMAGE
$ podman run --rm registry.redhat.io/rhel10/skopeo inspect --creds $USER:$PASSWORD docker://$IMAGECopy to Clipboard Copied! Toggle word wrap Toggle overflow
17.3. Running Skopeo in a container using authfiles Link kopierenLink in die Zwischenablage kopiert!
You can use an authentication file (authfile) to specify credentials. The skopeo login command logs into the specific registry and stores the authentication token in the authfile. The advantage of using authfiles is preventing the need to repeatedly enter credentials.
When running on the same host, all container tools such as Skopeo, Buildah, and Podman share the same authfile. When running Skopeo in a container, you have to either share the authfile on the host by volume-mounting the authfile in the container, or you have to reauthenticate within the container.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Inspect a remote container image using Skopeo against a locked registry:
podman run --rm -v $AUTHFILE:/auth.json registry.redhat.io/rhel10/skopeo inspect docker://$IMAGE
$ podman run --rm -v $AUTHFILE:/auth.json registry.redhat.io/rhel10/skopeo inspect docker://$IMAGECopy to Clipboard Copied! Toggle word wrap Toggle overflow The
-v $AUTHFILE:/auth.jsonoption volume-mounts an authfile at /auth.json within the container. Skopeo can now access the authentication tokens in the authfile on the host and get secure access to the registry.
Other Skopeo commands work similarly, for example:
-
Use the
skopeo-copycommand to specify credentials on the command line for the source and destination image using the--source-credsand--dest-credsoptions. It also reads the/auth.jsonauthfile. -
If you want to specify separate authfiles for the source and destination image, use the
--source-authfileand--dest-authfileoptions and volume-mount those authfiles from the host into the container.
17.4. Copying container images to or from the host Link kopierenLink in die Zwischenablage kopiert!
Skopeo, Buildah, and Podman share the same local container-image storage. If you want to copy containers to or from the host container storage, you need to mount it into the Skopeo container.
The path to the host container storage differs between root (/var/lib/containers/storage) and non-root users ($HOME/.local/share/containers/storage).
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Copy the
registry.access.redhat.com/ubi10/ubiimage into your local container storage:podman run --privileged --rm -v $HOME/.local/share/containers/storage:/var/lib/containers/storage \ registry.redhat.io/rhel10/skopeo skopeo copy \ docker://registry.access.redhat.com/ubi10/ubi containers-storage:registry.access.redhat.com/ubi10/ubi
$ podman run --privileged --rm -v $HOME/.local/share/containers/storage:/var/lib/containers/storage \ registry.redhat.io/rhel10/skopeo skopeo copy \ docker://registry.access.redhat.com/ubi10/ubi containers-storage:registry.access.redhat.com/ubi10/ubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
--privilegedoption disables all security mechanisms. Red Hat recommends only using this option in trusted environments. To avoid disabling security mechanisms, export the images to a tarball or any other path-based image transport and mount them in the Skopeo container:
-
$ podman save --format oci-archive -o oci.tar $IMAGE -
$ podman run --rm -v oci.tar:/oci.tar registry.redhat.io/rhel10/skopeo copy oci-archive:/oci.tar $DESTINATION
-
-
The
Optional: List images in local storage:
podman images
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.access.redhat.com/ubi10/ubi latest ecbc6f53bba0 8 weeks ago 211 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow
17.5. Running Buildah in a container Link kopierenLink in die Zwischenablage kopiert!
The procedure demonstrates how to run Buildah in a container and create a working container based on an image.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Log in to the registry.redhat.io registry:
podman login registry.redhat.io
$ podman login registry.redhat.io Username: myuser@mycompany.com Password: <password> Login Succeeded!Copy to Clipboard Copied! Toggle word wrap Toggle overflow Pull and run the
registry.redhat.io/rhel10/buildahimage:podman run --rm --device /dev/fuse -it \ registry.redhat.io/rhel10/buildah /bin/bash
# podman run --rm --device /dev/fuse -it \ registry.redhat.io/rhel10/buildah /bin/bashCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
The
--rmoption removes theregistry.redhat.io/rhel10/buildahimage after the container exits. -
The
--deviceoption adds a host device to the container. -
The
sys_chroot- capability to change to a different root directory. It is not included in the default capabilities of a container.
-
The
Create a new container using a
registry.access.redhat.com/ubi10/image:buildah from registry.access.redhat.com/ubi10/
# buildah from registry.access.redhat.com/ubi10/ ... ubi10/-working-containerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run the
ls /command inside theubi10/-working-containercontainer:buildah run --isolation=chroot ubi10/-working-container ls /
# buildah run --isolation=chroot ubi10/-working-container ls / bin boot dev etc home lib lib64 lost+found media mnt opt proc root run sbin srvCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all images in a local storage:
buildah images
# buildah images REPOSITORY TAG IMAGE ID CREATED SIZE registry.access.redhat.com/ubi10/ latest ecbc6f53bba0 5 weeks ago 211 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List the working containers and their base images:
buildah containers
# buildah containers CONTAINER ID BUILDER IMAGE ID IMAGE NAME CONTAINER NAME 0aaba7192762 * ecbc6f53bba0 registry.access.redhat.com/ub... ubi10/-working-containerCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Push the
registry.access.redhat.com/ubi10/image to the a local registry located onregistry.example.com:buildah push ecbc6f53bba0 registry.example.com:5000/ubi10/ubi
# buildah push ecbc6f53bba0 registry.example.com:5000/ubi10/ubiCopy to Clipboard Copied! Toggle word wrap Toggle overflow
17.6. Privileged and unprivileged Podman containers Link kopierenLink in die Zwischenablage kopiert!
By default, Podman containers are unprivileged and cannot, for example, modify parts of the operating system on the host. This is because by default a container is only allowed limited access to devices.
The following list emphasizes important properties of privileged containers. You can run the privileged container by using the podman run --privileged <image_name> command.
- A privileged container is given the same access to devices as the user launching the container.
- A privileged container disables the security features that isolate the container from the host. Dropped Capabilities, limited devices, read-only mount points, Apparmor/SELinux separation, and Seccomp filters are all disabled.
- A privileged container cannot have more privileges than the account that launched them.
17.7. Running Podman with extended privileges Link kopierenLink in die Zwischenablage kopiert!
If you cannot run your workloads in a rootless environment, you need to run these workloads as a root user. Running a container with extended privileges should be done judiciously, because it disables all security features.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Run the Podman container in the Podman container:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Run the outer container named
privileged_podmanbased on theregistry.access.redhat.com/ubi10/podmanimage. -
The
--privilegedoption disables the security features that isolate the container from the host. -
Run
podman run ubi10 echo hellocommand to create the inner container based on theubi10image. -
Notice that the
ubi10short image name was resolved as an alias. As a result, theregistry.access.redhat.com/ubi10:latestimage is pulled.
Verification
List all containers:
podman ps -a
$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 52537876caf4 registry.access.redhat.com/ubi10/podman podman run ubi10 e... 30 seconds ago Exited (0) 13 seconds ago privileged_podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
17.8. Running Podman with less privileges Link kopierenLink in die Zwischenablage kopiert!
You can run two nested Podman containers without the --privileged option. Running the container without the --privileged option is a more secure option.
This can be useful when you want to try out different versions of Podman in the most secure way possible.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Run two nested containers:
podman run --name=unprivileged_podman --security-opt label=disable \ --user podman --device /dev/fuse \ registry.access.redhat.com/ubi10/podman \ podman run ubi10 echo hello
$ podman run --name=unprivileged_podman --security-opt label=disable \ --user podman --device /dev/fuse \ registry.access.redhat.com/ubi10/podman \ podman run ubi10 echo helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Run the outer container named
unprivileged_podmanbased on theregistry.access.redhat.com/ubi10/podmanimage. -
The
--security-opt label=disableoption disables SELinux separation on the host Podman. SELinux does not allow containerized processes to mount all of the file systems required to run inside a container. -
The
--user podmanoption automatically causes the Podman inside the outer container to run within the user namespace. -
The
--device /dev/fuseoption uses thefuse-overlayfspackage inside the container. This option adds/dev/fuseto the outer container, so that Podman inside the container can use it. -
Run
podman run ubi10 echo hellocommand to create the inner container based on theubi10image. -
Notice that the ubi10 short image name was resolved as an alias. As a result, the
registry.access.redhat.com/ubi10:latestimage is pulled.
Verification
List all containers:
podman ps -a
$ podman ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a47b26290f43 podman run ubi10 e... 30 seconds ago Exited (0) 13 seconds ago unprivileged_podmanCopy to Clipboard Copied! Toggle word wrap Toggle overflow
17.9. Building a container inside a Podman container Link kopierenLink in die Zwischenablage kopiert!
You can run a container in a container using Podman. This example shows how to use Podman to build and run another container from within this container. The container will run "Moon-buggy", a simple text-based game.
Prerequisites
-
The
container-toolsmeta-package is installed. You are logged in to the registry.redhat.io registry:
podman login registry.redhat.io
# podman login registry.redhat.ioCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Run the container based on
registry.redhat.io/rhel10/podmanimage:podman run --privileged --name podman_container -it \ registry.redhat.io/rhel10/podman /bin/bash
# podman run --privileged --name podman_container -it \ registry.redhat.io/rhel10/podman /bin/bashCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Run the outer container named
podman_containerbased on theregistry.redhat.io/rhel10/podmanimage. -
The
--itoption specifies that you want to run an interactive bash shell within a container. -
The
--privilegedoption disables the security features that isolate the container from the host.
-
Run the outer container named
Create a
Containerfileinside thepodman_containercontainer:vi Containerfile
# vi Containerfile FROM registry.access.redhat.com/ubi10/ubi RUN dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm RUN dnf -y install moon-buggy && dnf clean all CMD ["/usr/bin/moon-buggy"]Copy to Clipboard Copied! Toggle word wrap Toggle overflow The commands in the
Containerfilecause the following build command to:-
Build a container from the
registry.access.redhat.com/ubi10/ubiimage. -
Install the
epel-release-latest-8.noarch.rpmpackage. -
Install the
moon-buggypackage. - Set the container command.
-
Build a container from the
Build a new container image named
moon-buggyusing theContainerfile:podman build -t moon-buggy .
# podman build -t moon-buggy .Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: List all images:
podman images
# podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/moon-buggy latest c97c58abb564 13 seconds ago 1.67 GB registry.access.redhat.com/ubi10/ubi latest 4199acc83c6a 132seconds ago 213 MBCopy to Clipboard Copied! Toggle word wrap Toggle overflow Run a new container based on a
moon-buggycontainer:podman run -it --name moon moon-buggy
# podman run -it --name moon moon-buggyCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Tag the
moon-buggyimage:podman tag moon-buggy registry.example.com/moon-buggy
# podman tag moon-buggy registry.example.com/moon-buggyCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Push the
moon-buggyimage to the registry:podman push registry.example.com/moon-buggy
# podman push registry.example.com/moon-buggyCopy to Clipboard Copied! Toggle word wrap Toggle overflow