Hello,
I’m having trouble getting my Flask app to bind to the port defined by the PORT
environment variable on Render. Here are the steps I’ve taken:
- Flask App Code: I’ve updated my Flask app to read the
HOST
andPORT
environment variables and bind to0.0.0.0
and10000
accordingly. Below is the relevant code snippet from myapp.py
:
if __name__ == "__main__":
app.run(host=os.getenv('HOST'), port=int(os.getenv('PORT'),8080), debug=False)
And here are my .env variables:
PORT = 10000
HOST = 0.0.0.0
Additional Details:
- The app works correctly when running locally and binds to the specified port.
- I’ve tried different port values and ensured that
host='0.0.0.0'
is set in theapp.run()
method. - I have also set HOST (0.0.0.0) and PORT (10000) as environment variables on Render’s UI
Despite these steps, my app does not seem to bind to the port defined by the PORT
environment variable when deployed on Render. The app works locally, but deployment fails on Render with the following error in the logs:
==> No open ports detected, continuing to scan...
==> Docs on specifying a port: https://render.com/docs/web-services#port-binding
==> Port scan timeout reached, no open ports detected. Bind your service to at least one port. If you don't need to receive traffic on any port, create a background worker instead.