Skip to content

fix: Docker HEALTHCHECK respects $PORT env var (#291)#292

Merged
kindralai[bot] merged 1 commit into
mainfrom
kindral/healthcheck-port-env
Jul 10, 2026
Merged

fix: Docker HEALTHCHECK respects $PORT env var (#291)#292
kindralai[bot] merged 1 commit into
mainfrom
kindral/healthcheck-port-env

Conversation

@kindralai

@kindralai kindralai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Problem

The HEALTHCHECK in the Dockerfile hardcodes port 8000, but the app port is configurable via the PORT environment variable. When a container is started with -e PORT=6100, the health check still probes port 8000 → connection refused → Docker marks the container unhealthy.

Solution

Changed:

CMD curl -f http://localhost:8000/health || exit 1

to:

CMD curl -f "http://localhost:${PORT:-8000}/health" || exit 1

Shell interpolates $PORT at health-check runtime, falling back to 8000 when unset. Zero code changes needed.

Acceptance criteria

  • HEALTHCHECK reads $PORT env var with fallback to 8000
  • Default run (no PORT set) → probes port 8000 (unchanged)
  • Custom port (-e PORT=6100) → probes port 6100
  • Zero code changes — purely a HEALTHCHECK CMD fix

Closes #291

The HEALTHCHECK CMD hardcoded port 8000, so containers with a
custom PORT env var were reported as unhealthy. Use ${PORT:-8000}
so the health probe respects the configured port.

@mattmezza mattmezza left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@kindralai
kindralai Bot merged commit cb346e8 into main Jul 10, 2026
3 checks passed
@kindralai
kindralai Bot deleted the kindral/healthcheck-port-env branch July 10, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant