HOW TO: Use $PORT to deploy Docker app on Heroku? (Python | Uvicorn)

Опубликовано: 22 Август 2026
на канале: chinamatt
1,621
15

Did you get this error when trying to deploy your docker app on Heroku?
“Web process failed to bind to $PORT within 60 seconds of launch”

When spinning up the webserver, we need to use the port number given to us by Heroku via the $PORT environment variable. To do this in python:

`port = os.getenv('PORT', default=8000)`

Then whatever library you use to start the webserver (uvicorn in the video), we pass this port variable to the function argument:

`uvicorn.run(app_str, host=host, port=port, reload=True)`