Demo, all content is generated
Question

Fly.io: instance refused connection. is your app listening on 0.0.0.0:8080?

Solved · 641 views · asked by vibeandchill · edited

Next.js with output: 'standalone' in Docker on Fly. fly logs:

[PC01] instance refused connection. is your app listening on 0.0.0.0:8080? make sure it is not only listening on 127.0.0.1

My Dockerfile ends with ENV PORT=8080 and CMD ["node", "server.js"]. Startup log says Local: http://a1b2c3d4e5f6:8080. Cursor swears the config is right.

What I’ve tried

Double checked internal_port = 8080 in fly.toml. Ran the container locally with docker run -p 8080:8080, that works.

Comment
What does the startup log line say exactly, which host does it print? pawel_z · edited

2 answers

Marked as helpful by the asker
rafa_dev · edited

Look at that startup line: it's listening on a1b2c3d4e5f6, not 0.0.0.0. The standalone server.js binds to process.env.HOSTNAME, and in a container HOSTNAME is set to the container's own name. On Fly that resolves to an address the proxy can't reach.

Add this to the Dockerfile, next to PORT:

ENV HOSTNAME="0.0.0.0"

The official Next.js Docker example has that line for exactly this reason. Locally it works because Docker's port mapping reaches it anyway.

Comment
The one line. Startup now says http://0.0.0.0:8080 and the app is live. Wild that the env var name collides like that. vibeandchill · edited
Yes, one of the more annoying ones. rafa_dev · edited
Same thing on Railway with standalone builds, saving this. old_school_raj · edited
chidi_eze · edited

While you're in fly.toml: give the machine at least 512 MB. A Next.js server on 256 MB tends to get OOM-killed under real traffic, which also shows up as 'refused connection' in the logs.

Comment
It was on 256. Bumped it, thanks vibeandchill · edited