Skip to content

Health-check metadata

The optional healthcheck table writes a Docker-compatible Healthcheck object into the image configuration. It is metadata only: pycontainer never runs the check, needs no Docker daemon to build, and does not validate that the command exists in the image.

[build.healthcheck]
mode = "exec"
command = ["/usr/local/bin/python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health')"]
interval-ms = 30000
timeout-ms = 5000
start-period-ms = 10000
retries = 3

In pyproject.toml use [tool.pycontainer.healthcheck]. Direct API callers pass the same mapping as BuildConfig(healthcheck={...}). There is no CLI flag.

Setting Meaning
mode Required. "exec" sets a command check; "none" disables an inherited check.
command Required for exec; forbidden for none. Nonempty list of strings, run directly without a shell. The first item must be nonempty; NUL characters are rejected.
interval-ms, timeout-ms, start-period-ms Optional, exec only. Integer milliseconds from 1 to 9223372036854 (the largest value whose nanoseconds fit a signed 64-bit integer).
retries Optional, exec only. Integer from 1 to 2147483647.

Keys may use hyphens or underscores, but not both spellings of one setting. Unknown keys, booleans, floats, strings for numbers, zero, negative values and overflow are rejected before any pull, cache access or output, including in dry-run mode. mode = "none" accepts no other settings.

  • exec writes {"Test": ["CMD", ...command], "Interval": ns, "Timeout": ns, "StartPeriod": ns, "Retries": n} with milliseconds converted to nanoseconds and keys in that fixed order. Unspecified fields are omitted, so the container runtime applies its own defaults; pycontainer does not hardcode them.
  • none writes {"Test": ["NONE"]}.
  • Without a healthcheck table, the base image’s Healthcheck (if any) is inherited byte-for-byte, including fields pycontainer does not model.
  • A configured table replaces the whole base object; base timings are not merged into it. A healthcheck table in a later configuration source (for example a --config file over pyproject.toml defaults) replaces the earlier table as a whole.
  • Every platform of a multi-platform index receives the same object.
  • Equal settings in any key order produce the same config digest.
  • OCI reserves config.Healthcheck without defining runtime behavior. The object follows Docker Engine’s image configuration for Linux images; other runtimes (Kubernetes probes, Podman with OCI format, containerd) may ignore it. Configure Kubernetes liveness/readiness probes separately.
  • Shell form (CMD-SHELL), start-interval, and Windows containers are not supported. Use an explicit interpreter, for example ["/bin/sh", "-c", "..."], when the base image has a shell.
  • ${NAME} build arguments are not expanded in healthcheck; the command is stored literally. Do not put secrets in the command: it is visible in the image configuration.
  • Dockerfile HEALTHCHECK is still reported as unsupported by Dockerfile import (#40); translate it manually.

scripts/check_healthcheck_runtime.py is an opt-in Linux check that imports generated images into a running Docker daemon with Skopeo and verifies a healthy check, an unhealthy check, none disabling an inherited check, and whole-object replacement of a base check. It pulls python:3.11-slim and has bounded waits:

Terminal window
PYTHONPATH=src timeout 600 python scripts/check_healthcheck_runtime.py --platform linux/amd64

It is not part of default pytest and is not release evidence.