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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.