From 53b6849c27848b76c9890c8d6aa0bad59e5a2513 Mon Sep 17 00:00:00 2001 From: dschlueter Date: Tue, 7 Jul 2026 09:53:33 +0200 Subject: [PATCH] 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 --- src/llamacppctl/docker_ops.py | 12 ++++++++++++ tests/test_docker_ops.py | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/llamacppctl/docker_ops.py b/src/llamacppctl/docker_ops.py index 46ccfaf..08e8f44 100644 --- a/src/llamacppctl/docker_ops.py +++ b/src/llamacppctl/docker_ops.py @@ -138,6 +138,18 @@ def build_run_command(cfg: ServerConfig) -> list: "-e", "HF_HOME=/hf_home", "-v", f"{cfg.hf_home}:/hf_home:ro", "-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, "-m", model_in_container, "--alias", cfg.model_alias, diff --git a/tests/test_docker_ops.py b/tests/test_docker_ops.py index ce21f5c..75a6c33 100644 --- a/tests/test_docker_ops.py +++ b/tests/test_docker_ops.py @@ -126,6 +126,16 @@ def test_build_run_command_contains_key_flags(): 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(): cfg = make_cfg(expose=True) cmd = build_run_command(cfg)