Red Hat Training

A Red Hat training course is available for RHEL 8

19.5. Buildah를 사용하여 처음부터 이미지 생성

기본 이미지로 시작하는 대신 최소 컨테이너 메타데이터 양을 보유하는 새 컨테이너를 생성할 수 있습니다.

스크래치 컨테이너에서 이미지를 생성할 때 다음을 고려하십시오.

  • 종속성이 없는 실행 파일을 스크래치 이미지에 복사하고 몇 가지 구성 설정을 사용하여 최소한의 컨테이너를 작업할 수 있습니다.
  • yum 또는 rpm 과 같은 도구를 사용하려면 RPM 데이터베이스를 초기화하고 컨테이너에 release 패키지를 추가해야 합니다.
  • 많은 패키지를 추가하는 경우 이미지 대신 표준 UBI 또는 최소 UBI 이미지를 사용하는 것이 좋습니다.

사전 요구 사항

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

절차

웹 서비스 httpd를 컨테이너에 추가하고 실행하도록 구성할 수 있습니다.

  1. 비어 있는 컨테이너를 생성합니다.

    # buildah from scratch
    working-container
  2. working-container 컨테이너를 마운트하고 마운트 지점 경로를 scratchmnt 변수에 저장합니다.

    # scratchmnt=$(buildah mount working-container)
    
    
    # echo $scratchmnt
    /var/lib/containers/storage/overlay/be2eaecf9f74b6acfe4d0017dd5534fde06b2fa8de9ed875691f6ccc791c1836/merged
  3. 스크래치 이미지 내에서 RPM 데이터베이스를 초기화하고 redhat-release 패키지를 추가합니다.

    # yum install -y --releasever=8 --installroot=$scratchmnt redhat-release
  4. httpd 서비스를 스크래치 디렉터리에 설치합니다.

    # yum install -y --setopt=reposdir=/etc/yum.repos.d \
          --installroot=$scratchmnt \
          --setopt=cachedir=/var/cache/dnf httpd
  5. $scratchmnt/var/www/html/index.html 파일을 생성합니다.

    # mkdir -p $scratchmnt/var/www/html
    # echo "Your httpd container from scratch works!" > $scratchmnt/var/www/html/index.html
  6. 컨테이너에서 직접 httpd 데몬을 실행하도록 working-container 를 구성합니다.

    # buildah config --cmd "/usr/sbin/httpd -DFOREGROUND" working-container
    # buildah config --port 80/tcp working-container
    # buildah commit working-container localhost/myhttpd:latest

검증

  1. 로컬 스토리지의 모든 이미지를 나열합니다.

    # podman images
    REPOSITORY                                 TAG     IMAGE ID      CREATED         SIZE
    localhost/myhttpd                          latest  08da72792f60  2 minutes ago   121 MB
  2. localhost/myhttpd 이미지를 실행하고 컨테이너와 호스트 시스템 간의 포트 매핑을 구성합니다.

    # podman run -p 8080:80 -d --name myhttpd 08da72792f60
  3. 웹 서버를 테스트합니다.

    # curl localhost:8080
    Your httpd container from scratch works!

추가 리소스

  • buildah-config 도움말 페이지
  • buildah-commit 도움말 페이지