Red Hat Training

A Red Hat training course is available for RHEL 8

7.7. UBI 기반 이미지 빌드

Buildah 유틸리티를 사용하여 컨테이너 파일에서 UBI 기반 웹 서버 컨테이너를 생성할 수 있습니다. 이미지에 재배포할 수 있는 Red Hat 소프트웨어만 포함하도록 모든 비UBI yum 리포지토리를 비활성화해야 합니다.

참고

UBI 최소 이미지의 경우 yum 대신 microdnf 를 사용합니다. RUN microdnf update -y && rm -rf /var/cache/yumRUN microdnf install httpd -y && microdnf clean all commands.

사전 요구 사항

  • container-tools 모듈이 설치되어 있습니다.

절차

  1. 컨테이너 파일 만들기:

    FROM registry.access.redhat.com/ubi8/ubi
    USER root
    LABEL maintainer="John Doe"
    # Update image
    RUN yum update --disablerepo=* --enablerepo=ubi-8-appstream-rpms --enablerepo=ubi-8-baseos-rpms -y && rm -rf /var/cache/yum
    RUN yum 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/ubi8/ubi:latest
    STEP 2: USER root
    STEP 3: LABEL maintainer="John Doe"
    STEP 4: RUN yum update --disablerepo=* --enablerepo=ubi-8-appstream-rpms --enablerepo=ubi-8-baseos-rpms -y
    ...
    Writing manifest to image destination
    Storing signatures
    --> f9874f27050
    f9874f270500c255b950e751e53d37c6f8f6dba13425d42f30c2a8ef26b769f2

검증 단계

  1. 웹 서버를 실행합니다.

    # podman run -d --name=myweb -p 80:80 johndoe/webserver
    bbe98c71d18720d966e4567949888dc4fb86eec7d304e785d5177168a5965f64
  2. 웹 서버를 테스트합니다.

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