22.3. Containerfile을 사용하여 상태 점검 수행
컨테이너 파일 의 HEALTHCHECK 명령을 사용하여 상태 점검을 설정할 수 있습니다.
사전 요구 사항
-
container-toolsmeta-package가 설치되어 있습니다.
절차
컨테이너
파일 만들기:$ cat Containerfile FROM registry.access.redhat.com/ubi8/httpd-24 EXPOSE 8080 HEALTHCHECK CMD curl http://localhost:8080 || exit 1참고HEALTHCHECK명령은Docker이미지 형식에서만 지원됩니다.oci이미지 형식의 경우 명령이 무시됩니다.컨테이너를 빌드하고 이미지 이름을 추가합니다.
$ 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컨테이너를 실행합니다.
$ podman run -dt --name=hc-container localhost/hc-containerhc-container컨테이너의 상태를 확인합니다.podman inspect명령을 사용합니다.$ podman inspect --format='{{json .State.Health.Status}}' hc-container healthypodman 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-containerpodman healthcheck run명령을 사용합니다.$ podman healthcheck run hc-container healthy