REMIX deploy needs PORT in env

I’ve just been banging my head against a wall for a few hours before having a ‘DOH!’ moment.

If you set up a new Remix app you need to make sure that the remix-serve app knows to use port 8080. It looks for the port number in the environment and this isn’t set by default (Remix uses 3000).

So you need to set it in the Dockerfile. This worked for me:

# Start the server by default, this can be overwritten at runtime
# Set the port to match fly's internal_port (which defaults to 8080) or nothing will work!
ENV PORT=8080
CMD [ "npm", "run", "start" ]

Sorry about that!

Just a heads up: I’m testing a new dockerfile generator for node apps, I hope to put it in production next week or so. If you are adventurous, you can try it now.

What it will do when it detects a remix app is to EXPOSE port 3000, and the fly.toml produced by flyctl launch will match this value.

1 Like

No worries. The Fly.io docs do say they recommend 8080 in many places, so I should have realised.

I just wanted to add this here so that if someone else starts searching for it they can find the answer.

Here’s the kind of errors you will see in your log:

[warn] Failed to proxy HTTP request (error: no known healthy instances found for route tcp/443. (hint: is your app shutdown? is there an ongoing deployment with a volume or using the 'immediate' strategy? if not, this could be a delayed state issue)). Retrying in 1000 ms (attempt 80)

[error] 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 (hint: look at your startup logs, servers often print the address they are listening on)

See also here for fixing it in reverse:

https://community.fly.io/t/remix-integration-sets-up-the-wrong-port-by-default/8396