For anyone who wants to host streamlit from a container, I believe that the following code must be included in every Dockerfile (not sure about the environment variables, that may have been specific to my app):
Hi @timforr and @Marc, I have a clarifying question for either of you. I am new to Docker and am trying to host my streamlit app in a container. I am having an issue, where when I try to run my docker container locally, it begins running, then almost immediately exits.
Here is my Dockerfile
# base of miniconda image
FROM continuumio/miniconda3
# 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
EXPOSE 8501
# copying all analysis code to image
COPY . .
# activate conda environment
SHELL ["/bin/bash", "-c", "source activate ./env"]
# run app
CMD streamlit run webapp/app.py
I build the image with docker image build -t st:app ., then attempt to run the container with docker run -p 8501:8501 st:app.
What steps would I need to change in order to then access my streamlit app at http://localhost:8501/? Thank you!
Thanks for the response! I made that change and it gave me a more helpful error message:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"streamlit\": executable file not found in $PATH": unknown.
ERRO[0001] error waiting for container: context canceled
I suppose this means that my conda environment is not getting installed/activated properly. From what I understand, they can be tricky to configure with Docker. I’ll keep tinkering with it. Thank you!
Then, I created a simpler Dockerfile, inspired by this blog:
# base image
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
EXPOSE 8501
# copy over and install packages
COPY requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt
# copying everything over
COPY . .
# run app
CMD streamlit run webapp/app.py
Finally, I built the image with docker image build -t st:app ., then ran the container with docker container run -p 8501:8501 st:app. After that, I could access my streamlit app at http://localhost:8501/
I encounter the same issue. docker exec -it streamlit-image-name into the container and running streamlit run app.py runs, but invoking it from the Dockerfile returns docker: Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"streamlit\": executable file not found in $PATH": unknown.