18.3. Performing a health check using a Containerfile
You can set a health check by using the HEALTHCHECK instruction in the Containerfile.
Prerequisites
-
The
container-toolsmeta-package is installed.
Procedure
Create a
Containerfile:$ cat Containerfile FROM registry.access.redhat.com/ubi10/httpd-24 EXPOSE 8080 HEALTHCHECK CMD curl http://localhost:8080 || exit 1참고The
HEALTHCHECKinstruction is supported only for thedockerimage format. For theociimage format, the instruction is ignored.Build the container and add an image name:
$ podman build --format=docker -t hc-container . STEP 1/3: FROM registry.access.redhat.com/ubi10/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 a680c6919fe6bf1a79219a1b3d6216550d5a8f83570c36d0dadfee1bb74b924eRun the container:
$ podman run -dt --name=hc-container localhost/hc-containerCheck the health status of the
hc-containercontainer:Using the
podman inspectcommand:$ podman inspect --format='{{json .State.Health.Status}}' hc-container healthyUsing the
podman pscommand:$ 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-containerUsing the
podman healthcheck runcommand:$ podman healthcheck run hc-container healthyFor more information, see
podman-healthcheck(1)andpodman-run(1)man pages on your system.