Skip to content

Docker HEALTHCHECK always probes port 8000 — container shows unhealthy when PORT env var is custom #291

Description

@kindralai

Problem

Docker reports the humux container as unhealthy even though the app is running fine.

a35866b3061f   ghcr.io/mattmezza/humux:latest   "uv run python -m co…"
3 hours ago   Up 3 hours (unhealthy)   0.0.0.0:6100->6100/tcp, [::]:6100->6100/tcp, 8000/tcp

Root cause

The HEALTHCHECK in the Dockerfile (Dockerfile:161-162) hardcodes port 8000:

HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
  CMD curl -f http://localhost:8000/health || exit 1

But the app's port is configurable at runtime via the PORT environment variable (main.py:507):

port=int(environ.get("PORT", "8000")),

When the container is started with -e PORT=6100 (or any non-default port), the app listens on that port, but the health check continues probing port 8000. curl -f http://localhost:8000/health gets a connection refused, Docker counts 3 failed retries, and marks the container unhealthy.

Proposed fix

Make the HEALTHCHECK read the PORT env var with a fallback to 8000:

HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
  CMD curl -f "http://localhost:${PORT:-8000}/health" || exit 1

This way:

  • Default run (no PORT set) → probes http://localhost:8000/health (unchanged behaviour)
  • Custom port (-e PORT=6100) → probes http://localhost:6100/health
  • Zero code changes — purely a HEALTHCHECK CMD fix

Acceptance criteria

  • HEALTHCHECK reads $PORT env var with :-8000 fallback
  • Container with default port reports healthy
  • Container with custom port (e.g. -e PORT=6100) reports healthy
  • start-period and retries settings are unchanged

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingin-progressIt means someone is working on this

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions