Container starts but app never binds to port — 502 Bad Gateway
timbrrn
HOBBYOP

2 months ago

Deploy logs show "Starting Container" and pre-start commands (prisma migrate) complete successfully, but the Node.js process never binds to PORT.

All requests return 502 with 15s timeout. No error in deploy logs — just silence after the start command runs. Build succeeds fine.

Solved$10 Bounty

Pinned Solution

domehane
FREE

2 months ago

Hello , based on what you described the silence after the start command is the key clue , two things to check:

first make sure your node app is actually listening on process.env.PORT and binding to 0.0.0.0 not localhost, railway injects the port dynamically so hardcoding 3000 or anything else won't work

second if your start command runs prisma migrate and then starts the server in the same command like "npx prisma migrate deploy && node server.js", try wrapping it in an explicit shell like /bin/sh -c "npx prisma migrate deploy && node server.js"

without the shell wrapper the node process sometimes never actually gets called after migrate exits

hope this help you :) let me know the result

2 Replies

Status changed to Awaiting Railway Response Railway 2 months ago


domehane
FREE

2 months ago

Hello , based on what you described the silence after the start command is the key clue , two things to check:

first make sure your node app is actually listening on process.env.PORT and binding to 0.0.0.0 not localhost, railway injects the port dynamically so hardcoding 3000 or anything else won't work

second if your start command runs prisma migrate and then starts the server in the same command like "npx prisma migrate deploy && node server.js", try wrapping it in an explicit shell like /bin/sh -c "npx prisma migrate deploy && node server.js"

without the shell wrapper the node process sometimes never actually gets called after migrate exits

hope this help you :) let me know the result


domehane

Hello , based on what you described the silence after the start command is the key clue , two things to check: first make sure your node app is actually listening on process.env.PORT and binding to 0.0.0.0 not [localhost](http://localhost), railway injects the port dynamically so hardcoding 3000 or anything else won't work second if your start command runs prisma migrate and then starts the server in the same command like "npx prisma migrate deploy && node server.js", try wrapping it in an explicit shell like /bin/sh -c "npx prisma migrate deploy && node server.js" without the shell wrapper the node process sometimes never actually gets called after migrate exits hope this help you :) let me know the result

timbrrn
HOBBYOP

2 months ago

That fixed it, thanks! Wrapping the start command in /bin/sh -c "..." did the trick. Server starts fine now :)


Status changed to Solved nico 2 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...