Red Hat Training

A Red Hat training course is available for RHEL 8

21.3. Containerfile을 사용하여 상태 점검 수행

컨테이너 파일HEALTHCHECK 명령을 사용하여 상태 점검을 설정할 수 있습니다.

사전 요구 사항

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

절차

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

    $ cat Containerfile
    FROM registry.access.redhat.com/ubi8/httpd-24
    EXPOSE 8080
    HEALTHCHECK CMD curl http://localhost:8080 || exit 1
    참고

    HEALTHCHECK 명령은 Docker 이미지 형식에서만 지원됩니다. oci 이미지 형식의 경우 명령이 무시됩니다.

  2. 컨테이너를 빌드하고 이미지 이름을 추가합니다.

    $ podman build --format=docker -t hc-container .
    STEP 1/3: FROM registry.access.redhat.com/ubi8/httpd-24
    STEP 2/3: EXPOSE 8080
    --> 5aea97430fd
    STEP 3/3: HEALTHCHECK CMD curl http://localhost:8080 || exit 1
    COMMIT health-check
    Successfully tagged localhost/health-check:latest
    a680c6919fe6bf1a79219a1b3d6216550d5a8f83570c36d0dadfee1bb74b924e
  3. 컨테이너를 실행합니다.

    $ podman run -dt --name=hc-container localhost/hc-container
  4. hc-container 컨테이너의 상태를 확인합니다.

    • podman inspect 명령을 사용합니다.

      $ podman inspect --format='{{json .State.Health.Status}}' hc-container
      healthy
    • podman ps 명령을 사용합니다.

      $ podman ps
      CONTAINER ID  IMAGE                 COMMAND               CREATED      STATUS          PORTS       NAMES
      a680c6919fe  localhost/hc-container:latest  /usr/bin/run-http...  2 minutes ago  Up 2 minutes (healthy) hc-container
    • podman healthcheck run 명령을 사용합니다.

      $ podman healthcheck run hc-container
      healthy