7.7. UBI ベースのイメージの構築

Buildah ユーティリティーを使用して、Containerfile から UBI ベースの Web サーバーコンテナーを作成できます。非 UBI dnf リポジトリーをすべて無効にして、イメージに再配布できる Red Hat ソフトウェアのみが含まれていることを確認する必要があります。

注記

UBI の最小イメージの場合は、dnf の代わりに microdnf を使用します。RUN microdnf update -y && rm -rf /var/cache/yum および RUN microdnf install httpd -y && microdnf clean all コマンド。

前提条件

  • container-tools メタパッケージがインストールされている。

手順

  1. Containerfile を作成します。

    FROM registry.access.redhat.com/ubi9/ubi
    USER root
    LABEL maintainer="John Doe"
    # Update image
    RUN dnf update --disablerepo=* --enablerepo=ubi-8-appstream-rpms --enablerepo=ubi-8-baseos-rpms -y && rm -rf /var/cache/yum
    RUN dnf install --disablerepo=* --enablerepo=ubi-8-appstream-rpms --enablerepo=ubi-8-baseos-rpms httpd -y && rm -rf /var/cache/yum
    # Add default Web page and expose port
    RUN echo "The Web Server is Running" > /var/www/html/index.html
    EXPOSE 80
    # Start the service
    CMD ["-D", "FOREGROUND"]
    ENTRYPOINT ["/usr/sbin/httpd"]
  2. コンテナーイメージをビルドします。

    # buildah bud -t johndoe/webserver .
    STEP 1: FROM registry.access.redhat.com/ubi9/ubi:latest
    STEP 2: USER root
    STEP 3: LABEL maintainer="John Doe"
    STEP 4: RUN dnf update --disablerepo=* --enablerepo=ubi-8-appstream-rpms --enablerepo=ubi-8-baseos-rpms -y
    ...
    Writing manifest to image destination
    Storing signatures
    --> f9874f27050
    f9874f270500c255b950e751e53d37c6f8f6dba13425d42f30c2a8ef26b769f2

検証手順

  1. Web サーバーを実行します。

    # podman run -d --name=myweb -p 80:80 johndoe/webserver
    bbe98c71d18720d966e4567949888dc4fb86eec7d304e785d5177168a5965f64
  2. Web サーバーをテストします。

    # curl http://localhost/index.html
    The Web Server is Running