Anyone able to deploy to heroku using docker?

Hi alll,

i was able to deploy via AWS(docker)
and heroku using the normal way

how the normal way at heroku and using docker.

my files are as follows

Questions:

  1. Do I need to expose the port since heroku auto-assign ports? How do I do it?
  2. How do I execute setup.sh at Docker?

Better still is there a guide that I can follow?

Thanks.

requirements.txt

streamlit==0.63
pandas==1.0.5
numpy==1.19
scikit-learn==0.22
matplotlib==3.2.2

setup.sh

mkdir -p ~/.streamlit/
echo "\
[general]\n\
email = \"guest@hotmail.com\"\n\
" > ~/.streamlit/credentials.toml
echo "\
[server]\n\
headless = true\n\
enableCORS=false\n\
port = $PORT\n\
" > ~/.streamlit/config.toml

procfile

web: sh setup.sh && streamlit run app.py

Docker

FROM python:3.7

exposing default port for streamlit

EXPOSE 8501

making directory of app

WORKDIR /app

copy over requirements

COPY requirements.txt ./requirements.txt

install pip then packages

RUN pip install -r requirements.txt

copying all files over

COPY . .

cmd to launch app when container is run

CMD streamlit run app.py

If you are pushing to heroku using docker, you don’t need setup.sh and Procfile.


Regards to exposing port to Heroku, try changing your CMD in Dockerfile to CMD streamlit run app.py --server.port $PORT and follow the heroku guideline to push your docker image to the server

2 Likes

Is there an example guide?

Based on what you said.

  1. should I copy setup.sh to Dockers file
  2. do I need to remove the EXPOSE 8501 line ?

I think I did google search already but there isn’t much of a docker/streamlit/heroku combo. Most stop at the steps described above. Maybe because of the free tier.

  1. As I said, you don’t need setup.sh and Procfile file if you are deploying with container registry (in this case Docker)
    Your root directory would have requirements.txt, app.py, Dockerfile and anything else that you need to run your app.py. Simply just remove setup.sh and Procfile from the directory

  2. EXPOSE 8501 will be ignored by Heroku, so it’s up to you to keep it in Dockerfile. I would leave it in case you want to test docker container locally.

Hi, this is my Docker file. Would this be correct? and I just need to follow the heroku guideline link that you’ve provided? Thanks.

> FROM python:3.7
> 
> # streamlit-specific commands
> RUN mkdir -p /root/.streamlit
> RUN bash -c 'echo -e "\
> [general]\n\
> email = \"\"\n\
> " > /root/.streamlit/credentials.toml'
> RUN bash -c 'echo -e "\
> [server]\n\
> enableCORS = false\n\
> " > /root/.streamlit/config.toml'
> 
> # exposing default port for streamlit
> # heroku will ignore even if it's there
> EXPOSE 8501
> 
> # making directory of app
> WORKDIR /app
> 
> # copy over requirements
> COPY requirements.txt ./requirements.txt
> 
> # install pip then packages
> RUN pip install -r requirements.txt
> 
> # copying all files over
> COPY . .
> 
> # cmd to launch app when container is run
> CMD streamlit run app.py --server.port $PORT