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-tools meta-package is installed.
  • You are logged in to the registry.redhat.io registry:

    # podman login registry.redhat.io

Procedure

  1. Run the container based on registry.redhat.io/rhel10/podman image:

    # podman run --privileged --name podman_container -it \
      registry.redhat.io/rhel10/podman /bin/bash
    • Run the outer container named podman_container based on the registry.redhat.io/rhel10/podman image.
    • The --it option specifies that you want to run an interactive bash shell within a container.
    • The --privileged option disables the security features that isolate the container from the host.
  2. Create a Containerfile inside the podman_container container:

    # 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 Containerfile cause the following build command to:

    • Build a container from the registry.access.redhat.com/ubi10/ubi image.
    • Install the epel-release-latest-8.noarch.rpm package.
    • Install the moon-buggy package.
    • Set the container command.
  3. Build a new container image named moon-buggy using the Containerfile:

    # podman build -t moon-buggy .
  4. 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 MB
  5. Run a new container based on a moon-buggy container:

    # podman run -it --name moon moon-buggy
  6. Optional: Tag the moon-buggy image:

    # podman tag moon-buggy registry.example.com/moon-buggy
  7. Optional: Push the moon-buggy image to the registry:

    # podman push registry.example.com/moon-buggy
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部