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)