Skip to content

fix(docker): pin standalone bind host against runtime HOSTNAME injection#1005

Closed
jee7s wants to merge 1 commit into
mainfrom
fix/standalone-bind-hostname
Closed

fix(docker): pin standalone bind host against runtime HOSTNAME injection#1005
jee7s wants to merge 1 commit into
mainfrom
fix/standalone-bind-hostname

Conversation

@jee7s

@jee7s jee7s commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Problem

v1.0.0 prod deploy failed at Deploy to ECS (run 29422682506): every task exited 1 at boot with

⨯ Failed to start server
Error: getaddrinfo EAI_AGAIN default

Root cause

The Next standalone server.js binds to process.env.HOSTNAME || '0.0.0.0'. The Dockerfile sets ENV HOSTNAME=0.0.0.0, but ECS Managed Instances host-network tasks set a container hostname at create time, which injects HOSTNAME=default into the runtime env over the image ENV. The server then tries to bind to a host literally named default → DNS failure → exit 1 → crash loop → services-stable waiter timeout.

Dev never hit this: Fargate/awsvpc doesn't support container hostnames, so nothing overrides the image ENV.

Fix

Pin the bind address in the CMD itself — sh -c "HOSTNAME=0.0.0.0 exec node …" — so no runtime injection can override it. exec keeps node as PID 1 for signal handling. The migrate task overrides the command entirely and is unaffected.

Verified: env HOSTNAME=default sh -c 'HOSTNAME=0.0.0.0 exec node -p "process.env.HOSTNAME"'0.0.0.0; CI's deploy-build smoke test boots the image with the new CMD.

After merge: delete + re-cut the v1.0.0 release (third time — migrations already applied and are idempotent).

🤖 Generated with Claude Code

The v1.0.0 prod rollout crash-looped: every task exited 1 at boot with
'Failed to start server: getaddrinfo EAI_AGAIN default'. The Next
standalone server listens on $HOSTNAME (next/dist/build/utils.js), and
ECS Managed Instances host-network tasks set a container hostname at
create time, injecting HOSTNAME=default into the runtime env over the
image's ENV HOSTNAME=0.0.0.0. Fargate/awsvpc (dev) never injects, which
is why only prod hit it.

Pin the bind address in the CMD itself so no runtime injection can
override it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jee7s
jee7s requested review from dkaygithub and thpr July 15, 2026 15:15
@jee7s

jee7s commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by infra#124 — same root cause, fixed via task-def environment instead so dev and prod env definitions stay identical (per review discussion; task-def env wins over the runtime injection, vercel/next.js#58657).

@jee7s jee7s closed this Jul 15, 2026
@jee7s
jee7s deleted the fix/standalone-bind-hostname branch July 15, 2026 15:36
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.

2 participants