22.3. Containerfile を使用してヘルスチェックを実行する
Containerfile で HEALTHCHECK 命令を使用してヘルスチェックを設定できます。
前提条件
-
container-toolsメタパッケージがインストールされている。
手順
Containerfileを作成します。$ 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