- Title Deployment Crash: "'PORT' is not a valid port number"
2 months ago
Issue Summary: My application is crashing immediately upon deployment in the latest build (a738a9be). However, the previous build (ddde6fd0) was fully functional and stable.
Error Message: The deployment logs consistently show the following error: {"message": "Error: 'PORT' is not a valid port number.", "severity": "error"}
Comparative Logs:
- Current Failed Build (
a738a9be): The system fails to initialize the web server, reporting an invalidPORTvariable. - Previous Successful Build (
ddde6fd0): The application started correctly with the log:[2026-03-16 15:29:23 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080
Technical Details:
- Framework: Flask (Python) using Gunicorn.
- Database: MySQL (Status: Online).
- Environment: The application uses environment variables for DB configuration and port binding.
- Attempted Fixes: I have reviewed the environment variables in the Railway dashboard, but the crash persists. It seems the
$PORTinjected by the platform is being interpreted as an invalid value in this specific deployment.
3 Replies
Status changed to Awaiting Railway Response Railway • 2 months ago
2 months ago
Hello, the error means gunicorn is receiving the literal string "port" instead of a number , so the variable isn't being expanded at all , my question is are you using a dockerfile ? if yes an you share your cmd line, because if it looks like this: cmd ["gunicorn", "--bind", "0.0.0.0:$port", "app:app"] that's your prblm , docker's exec form (json array) doesn't expand env variables so $PORT never gets resolved. the fix is to change it to the shell form,
like this: CMD gunicorn --bind 0.0.0.0:$PORT app:app
2 months ago
if you're not using a dockerfile, can you share your procfile or start command so ican see where the value stops being expanded
2 months ago
Check your railway.toml file and remove the startCommand line entirely. Let it be in the Dockerfile. - this worked for me
