From 7c91182111f8bfcd44d00052ac4258273f0d5ac5 Mon Sep 17 00:00:00 2001 From: Lucas Rayan Date: Thu, 23 Jul 2026 06:51:28 -0300 Subject: [PATCH] #1: fix webmail healthcheck - Next standalone binds IPv4-only, wget resolved localhost to ::1 Verified live via WSL Docker (docker compose up --wait): every other F0 service came up healthy, but web stayed unhealthy. Root cause was two compounding issues, both invisible to static review: 1. Docker auto-sets HOSTNAME to the container ID; Next's standalone server.js honors that env var and binds only to it instead of all interfaces. Fixed by explicitly setting ENV HOSTNAME=0.0.0.0 in the Dockerfile, after Docker's automatic assignment. 2. Even bound to 0.0.0.0 (IPv4), the healthcheck's `wget http://localhost` resolved localhost to ::1 (IPv6) first inside the container, where nothing was listening. Fixed by pointing the healthcheck at 127.0.0.1 explicitly instead of localhost. Full stack (db, redis, migrate, auth, storage, protocols, web) now reaches healthy end-to-end under docker compose up --wait. --- docker-compose.yaml | 2 +- services/webmail/Dockerfile | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 677b9dc..5675d39 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -118,7 +118,7 @@ services: auth: { condition: service_healthy } storage: { condition: service_healthy } healthcheck: - test: ["CMD-SHELL", "wget -qO- http://localhost:3000/health || exit 1"] + test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3000/health || exit 1"] interval: 10s timeout: 5s retries: 5 diff --git a/services/webmail/Dockerfile b/services/webmail/Dockerfile index ea4ce0d..4da61b9 100644 --- a/services/webmail/Dockerfile +++ b/services/webmail/Dockerfile @@ -11,4 +11,8 @@ COPY --from=build /app/.next/standalone ./ COPY --from=build /app/.next/static ./.next/static COPY --from=build /app/public ./public EXPOSE 3000 +# Docker sets HOSTNAME to the container ID by default; Next's standalone +# server.js honors that env var and binds only to it, refusing localhost +# (and thus the healthcheck). Force it to listen on every interface. +ENV HOSTNAME=0.0.0.0 CMD ["node", "server.js"]