Skip to content

docs: explain intermittent Bad Gateway for Next.js standalone in Compose - #184

Open
Hayyan612 wants to merge 1 commit into
Dokploy:mainfrom
Hayyan612:docs/nextjs-standalone-hostname
Open

Hayyan612 wants to merge 1 commit into
Dokploy:mainfrom
Hayyan612:docs/nextjs-standalone-hostname

Conversation

@Hayyan612

Copy link
Copy Markdown
Contributor

Refs Dokploy/dokploy#5074

Adds the docs note that issue asks for, under Troubleshooting > Domains & Traefik > Getting "Bad Gateway Error", next to the existing Vite example.

A Next.js app built with output: "standalone" listens on process.env.HOSTNAME || '0.0.0.0' (packages/next/src/build/utils.ts), and Docker sets HOSTNAME to the container ID. For a Compose service with a domain, addDokployNetworkToService attaches both dokploy-network and default, so the ID has two entries in /etc/hosts and the app binds only one of them. Traefik dials the dokploy-network address (traefik.docker.network=dokploy-network), so deploys that bind the default network address return Bad Gateway until the next redeploy.

Reproduction

Docker 28.5, Compose 2.40. A Compose service on [dokploy-network, default], the shape Dokploy generates, running a server that picks its host the same way as Next.js standalone, requested from a separate container on dokploy-network via the service's dokploy-network IP, as Traefik does:

HOSTNAME=<container id>, 8 fresh deploys:
bound=172.21.0.2  dokploy-network ip=172.20.0.2  -> ECONNREFUSED
bound=172.20.0.2  dokploy-network ip=172.20.0.2  -> 200
bound=172.20.0.2  dokploy-network ip=172.20.0.2  -> 200
bound=172.20.0.2  dokploy-network ip=172.20.0.2  -> 200
bound=172.21.0.2  dokploy-network ip=172.20.0.2  -> ECONNREFUSED
bound=172.21.0.2  dokploy-network ip=172.20.0.2  -> ECONNREFUSED
bound=172.20.0.2  dokploy-network ip=172.20.0.2  -> 200
bound=172.20.0.2  dokploy-network ip=172.20.0.2  -> 200

HOSTNAME=0.0.0.0, 4 fresh deploys: bound=0.0.0.0 -> 200 every time

Both fixes in the note were checked: ENV HOSTNAME="0.0.0.0" in the image and environment: HOSTNAME=0.0.0.0 in Compose each override Docker's default, and the container's hostname itself is unchanged. The Dockerfile form matches the official Next.js Docker example.

Next.js standalone listens on process.env.HOSTNAME, which Docker sets to
the container ID. A Compose service with a domain is attached to both
dokploy-network and the default network, so the ID resolves to two
addresses and the app binds only one. Document setting HOSTNAME=0.0.0.0.
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.

1 participant