Port Issue: Deploy Streamlit app to Heroku by Docker Containners

Hi,
I am trying to package a tensorflow image classification app with streamlit UI.
I have pushed the image and a URL to my app page was generated.
But it fails to load the streamlit UI. On inspecting the logs, I found this.

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

In my Dockerfile:

# bind port
EXPOSE 8501

However, Heroku does not support this. (https://devcenter.heroku.com/articles/container-registry-and-runtime#dockerfile-commands-and-runtime)

  • EXPOSE - While EXPOSE can be used for local testing, it is not supported in Heroku’s container runtime. Instead your web process/code should get the $PORT environment variable.

Any idea how to bind ports properly from streamlit to heroku?

Hey @tourist-C

Heroku exposes the available port with the PORT environment variable so you need to use this in your Dockerfile,

CMD ["sh", "-c", "streamlit run --server.port $PORT path_to_your_main.py"] 

And you can add this in your docker-compose so that you wont have to change it at the time of deployment,

environment:
            - PORT=8000

Hope it helps !

Also this might help, Deploying Streamlit Apps with Docker on Heroku

1 Like