fix(docker): override image healthcheck to the configured port

The ghcr.io llama.cpp image bakes in a HEALTHCHECK that curls port 8080
(the llama.cpp default). When the server runs on a different --port (here
8000), that check always fails and Docker reports the container as
"unhealthy" even though it serves fine. Override the healthcheck in the
docker run command to target the configured container_port/health_endpoint,
with a 300s start-period so large-context model loads don't flap.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Dieter Schlüter 2026-07-07 09:53:33 +02:00
commit 53b6849c27
2 changed files with 22 additions and 0 deletions

View file

@ -138,6 +138,18 @@ def build_run_command(cfg: ServerConfig) -> list:
"-e", "HF_HOME=/hf_home", "-e", "HF_HOME=/hf_home",
"-v", f"{cfg.hf_home}:/hf_home:ro", "-v", f"{cfg.hf_home}:/hf_home:ro",
"-p", _port_publish(cfg), "-p", _port_publish(cfg),
# Override the image's baked-in HEALTHCHECK (curl on the llama.cpp
# default port 8080), which reports "unhealthy" whenever the server runs
# on a different --port. Point it at the actually configured port so
# Docker's health status matches reality.
"--health-cmd",
f"curl -f http://localhost:{cfg.container_port}{cfg.health_endpoint} || exit 1",
"--health-interval", "30s",
"--health-timeout", "5s",
"--health-retries", "3",
# Model load (large ctx) can take minutes; don't flap as unhealthy while
# it warms up.
"--health-start-period", "300s",
cfg.image, cfg.image,
"-m", model_in_container, "-m", model_in_container,
"--alias", cfg.model_alias, "--alias", cfg.model_alias,

View file

@ -126,6 +126,16 @@ def test_build_run_command_contains_key_flags():
assert "--cont-batching" in cmd assert "--cont-batching" in cmd
def test_build_run_command_overrides_healthcheck_to_configured_port():
cfg = make_cfg()
cmd = build_run_command(cfg)
assert "--health-cmd" in cmd
# healthcheck must target the configured container_port (8000), not the
# image default (8080), and hit the configured health endpoint.
assert "curl -f http://localhost:8000/health || exit 1" in cmd
assert "--health-start-period" in cmd
def test_build_run_command_expose_binds_all_interfaces(): def test_build_run_command_expose_binds_all_interfaces():
cfg = make_cfg(expose=True) cfg = make_cfg(expose=True)
cmd = build_run_command(cfg) cmd = build_run_command(cfg)