2.4. Building customized images by using podman build


Starting with RHEL 9.6, you can continue to use RHEL image builder to create edge installation images. You can also use image mode for RHEL to compose container images and create disk images for deployment. If you want to continue to use RHEL image builder, see Composing, installing, and managing RHEL for Edge images.

To use image mode for RHEL to create new disk images, follow the steps:

2.4.1. Using image mode to create a 9.6 RHEL for Edge image

To build an image mode RHEL for an edge host, create a Containerfile with instructions. Then use bootc-image-builder to install the created edge host by using an anaconda ISO.

Prerequisites

  • You have Podman installed on your host machine.
  • You have root access to run the bootc-image-builder tool, and run the containers in --privileged mode, to build the images.

Procedure

  1. Create a Containerfile, for example:

    $ cat Containerfile
    FROM registry.redhat.io/rhel9/rhel-bootc:9.6
    
    # Packages
    RUN dnf install -y zsh && dnf clean all
    
    # Group install
    RUN dnf group -y install "Development Tools"
    
    # Hostname
    RUN echo "rock.paper.scissor" > /etc/hostname
    
    # Kernel
    RUN mkdir -p /usr/lib/bootc/kargs.d
    RUN cat <<EOF >> /usr/lib/bootc/kargs.d/console.toml
    kargs = ["console=ttyS0,114800n8","kernel-debug"]
    match-architectures = ["x86_64"]
    EOF
    
    # Subscription-manager
    RUN dnf install subscription-manager
    
    # RPM config
    RUN mkdir -p /etc/pki/rpm-gpg/
    COPY <host_path>/gpg_key /etc/pki/rpm-gpg/gpg_key
    
    # Timezones
    RUN cat <<EOF >> /etc/localtime
    Asia/Bangkok
    EOF
    
    
    # Locale
    RUN cat <<EOF >> /etc/locale.conf
    LANG="en_US.UTF-8"
    EOF && \
    cat <<EOF >> /etc/vconsole.conf
    KEYMAP=us
    EOF
    
    
    # firewall
    RUN dnf install -y firewalld && \
        mkdir -p /etc/firewalld/zones
    RUN cat <<EOF >> /etc/firewalld/zones/customzone.xml
    <?xml version="1.0" encoding="utf-8"?>
    <zone>
        <short>Customzone</short>
        <description>Custom firewall rules for the container.</description>
    
        <!-- Allowed services -->
        <service name="ftp"/>
        <service name="ntp"/>
        <service name="dhcp"/>
    
        <!-- Blocked services (not explicitly listed) -->
        <!-- Removing telnet explicitly is unnecessary if it is not included -->
    
        <!-- Open specific ports -->
        <port protocol="tcp" port="22"/>
        <port protocol="tcp" port="80"/>
        <port protocol="tcp" port="53"/>
        <port protocol="udp" port="53"/>
        <port protocol="tcp" port="30000-32767"/>
        <port protocol="udp" port="30000-32767"/>
    </zone>
    EOF
    RUN firewall-offline-cmd --set-default-zone=customzone
    
    # systemd services
    RUN systemctl enable sshd
    
    #ignition
    RUN mkdir -p /usr/lib/bootc/kargs.d && \
    cat <<EOF >> /usr/lib/bootc/kargs.d/console.toml
    kargs = ["ignition.config.url=http://192.168.122.1/fiot.ign","rd.neednet=1"]
    EOF
    
    #fdo
    RUN dnf install -y fdo-init fdo-client && \
    systemctl enable fdo-client-linuxapp.service
    
    #Repositories
    RUN mkdir -p /etc/yum.repos.d
    COPY custom.repo /etc/yum.repos.d/custom.repo
    
    #fips
    RUN mkdir -p /usr/lib/bootc/kargs.d && \
    cat <<EOF >>  /usr/lib/bootc/kargs.d/01-fips.toml
    kargs = ["fips=1"]
    EOF
    RUN dnf install -y crypto-policies-scripts && update-crypto-policies --no-reload --set FIPS
  2. Build the <image> image by using Containerfile in the current directory:

    $ podman build -t quay.io/<namespace>/<image>:<tag> .

Verification

  • List all images:

    $ podman images
    REPOSITORY                                  TAG      IMAGE ID       CREATED              SIZE
    quay.io/<namespace>/<image>                          latest   b28cd00741b3   About a minute ago   2.1 GB

2.4.2. Using image mode to create a RHEL 10 for Edge image

From RHEL 10 and later, to create new RHEL for Edge images installations, use bootc, because RHEL image builder no longer supports edge artifacts.

注意

Not all the available RHEL image builder artifacts are available in image mode. That means that you cannot create certain image types by using bootc-image-builder.

  • Notably, the simplified-installer no longer exists. Instead, use the bootc-image-builder Anaconda ISO for workflows such as FDO.

Prerequisites

  • You have Podman installed on your host machine.
  • You have root access to run the bootc-image-builder tool, and run the containers in --privileged mode, to build the images.

Procedure

  1. Create a Containerfile. The following example contains several customizations that you can use as an example, and can be removed in case it does not suit your requirements.

    $ cat Containerfile
    FROM registry.redhat.io/rhel10/rhel-bootc:10.0
    
    # Packages
    RUN dnf install -y zsh && dnf clean all
    
    # Group install
    RUN dnf group -y install "Development Tools"
    
    # Kernel
    RUN mkdir -p /usr/lib/bootc/kargs.d
    RUN cat <<EOF >> /usr/lib/bootc/kargs.d/console.toml
    kargs = ["console=ttyS0,114800n8","kernel-debug"]
    match-architectures = ["x86_64"]
    EOF
    
    # Subscription-manager
    COPY ./rhsm.conf /etc/rhsm/rhsm.conf
    
    # RPM config
    RUN mkdir -p /etc/pki/rpm-gpg/
    COPY <host_path>/gpg_key /etc/pki/rpm-gpg//gpg_key
    
    # Additional groups
    RUN groupadd -g 1001 widget
    
    # Timezones
    RUN ln -sf /usr/share/zoneinfo/Asia/Bangkok /etc/localtime
    
    # Locale
    RUN cat <<EOF >> /etc/locale.conf
    LANG="en_US.UTF-8"
    EOF && \
    cat <<EOF >> /etc/vconsole.conf
    KEYMAP=us
    EOF
    
    
    # firewall
    RUN dnf install -y firewalld && \
        dnf clean all && \
        firewall-offline-cmd --new-zone=customzone && \
        firewall-offline-cmd --zone=customzone --set-description="Custom firewall rules for the container" && \
        firewall-offline-cmd --zone=customzone --add-service=ftp && \
        firewall-offline-cmd --zone=customzone --add-service=ntp && \
        firewall-offline-cmd --zone=customzone --add-service=dhcp && \
        firewall-offline-cmd --zone=customzone --add-port=22/tcp && \
        firewall-offline-cmd --zone=customzone --add-port=80/tcp && \
        firewall-offline-cmd --zone=customzone --add-port=53/tcp && \
        firewall-offline-cmd --zone=customzone --add-port=53/udp && \
        firewall-offline-cmd --zone=customzone --add-port=30000-32767/tcp && \
        firewall-offline-cmd --zone=customzone --add-port=30000-32767/udp && \
        firewall-offline-cmd --set-default-zone=customzone
    
    # systemd services
    RUN systemctl enable httpd sshd && \
    systemctl disable telnetd && \
    systemctl mask rcpbind
  2. Build the <image> image by using Containerfile in the current directory:

    $ podman build -t quay.io/<namespace>/<image>:<tag> .

Verification

  • List all images:

    $ podman images
    REPOSITORY                                  TAG      IMAGE ID       CREATED              SIZE
    quay.io/<namespace>/<image>                           latest   b28cd00741b3   About a minute ago   2.1 GB
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat
返回顶部