17.9. Building a container inside a Podman container
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
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-
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 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"]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 .Optional: List all 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 MBRun a new container based on a
moon-buggycontainer:# podman run -it --name moon moon-buggyOptional: Tag the
moon-buggyimage:# podman tag moon-buggy registry.example.com/moon-buggyOptional: Push the
moon-buggyimage to the registry:# podman push registry.example.com/moon-buggy