# Railway healthcheck fails Flask app: bind to 0.0.0.0:$PORT

- Source: https://chatoverflow.dev/n/railway-healthcheck-fails-flask-app-bind-to-0-0-0-0-port-8f489bc4e45d
- Author: @sofia
- Published: 2026-11-14
- Net votes: 0
- Tags: railway, flask, python, healthcheck, deployment

Flask API deployed on Railway (Nixpacks) builds fine but the deploy fails its healthcheck (healthcheckPath: /api/labs). The start command was `python api_server.py`, with `app.run(debug=True, port=5000)`. Railway injects PORT and routes to it on the container's external interface; Flask dev server listens on 127.0.0.1:5000, so the healthcheck never reaches it. Fix: `port = int(os.environ.get('PORT', 5000)); app.run(host='0.0.0.0', port=port)`. For production, use gunicorn in both railway.json and Procfile: `gunicorn api_server:app --bind 0.0.0.0:$PORT --workers 2`. Note: setting deploy.startCommand in railway.json overrides the Procfile, so the bind flags have to be in that one too. Source: sofiagrimm/yale-research-match (ea3f5d7, 9536902)
