10 months ago
My Dockerfile uses CMD ["sh", "-c", "gunicorn main:app --bind 0.0.0.0:${PORT:-5000}"], but Railway doesn’t inject the $PORTvariable as expected — so it falls back or binds incorrectly (e.g. to 8080). This leads to 502 errors unless I hardcode 5000. Please confirm if this is a platform issue or if there’s a workaround.
5 Replies
10 months ago
Heya,
I checked out your project and I think you figured it out. Your public domain is now properly bound to 5000 and your website is accessible. Were you still having this issue?
Status changed to Awaiting User Response Railway • 11 months ago
Status changed to Solved echohack • 11 months ago
echohack
Heya,I checked out your project and I think you figured it out. Your public domain is now properly bound to 5000 and your website is accessible. Were you still having this issue?
10 months ago
Hi — thanks for checking!
The issue is that Railway does not automatically inject the $PORT environment variable inside Dockerfile builds.
It only works now because I hardcoded port 5000. Ideally, Railway should inject $PORT into the container’s runtime environment automatically (like Render and Heroku do), so we can bind dynamically with gunicorn main:app bind 0.0.0.0:${PORT} instead of hardcoding it. Otherwise dynamic deployment won’t work properly without manual fixes and no one would ever know the reason for the error due to expectancies and no log warning without many hours of debugging which is what I went through. Thanks for your help.
Status changed to Awaiting Railway Response Railway • 11 months ago
Status changed to Awaiting User Response Railway • 11 months ago
brody
Hello,8080 is what we always inject the PORT variable as!
10 months ago
Thanks for clarifying!
I understand that $PORT should be 8080 — but the real issue is that in Dockerfile-based builds, the $PORT environment variable doesn’t get injected at all inside the container.
When my app tries to bind to ${PORT}, it’s empty (undefined), so it defaults to 5000 (or errors).
Can you confirm if Railway injects $PORT into the runtime for Docker builds, like it does for Nixpacks? Or is manual env var setup required for Docker?
Thanks again for your help!
Status changed to Awaiting Railway Response Railway • 11 months ago
10 months ago
Yes Railway injects PORT as 8080 during and only during runtime regardless of the type or source of deployment.
Status changed to Awaiting User Response Railway • 10 months ago
Status changed to Solved brody • 10 months ago