Streamlit Docker (.streamlit files)


I am deploying my application using docker container. While I build and test the docker image in the local, It works perfectly fine. But when I deploy it to the Azure server I get Bad Gateway error. I though this might be due to CORS issue and learned from community discussions to use .streamlit folder and reference the 2 line code in the Dockerfile, so the issue might be resolved.
RUN mkdir ~/.streamlit
RUN cp .streamlit/ ~/.streamlit/config.toml

I had copied these files to my project folder. But while building the docker image, I get this below error.

=> ERROR [7/7] RUN cp .streamlit/ ~/.streamlit/config.toml                                                                                                                0.3s
 > [7/7] RUN cp .streamlit/ ~/.streamlit/config.toml:
#11 0.227 cp: cannot stat '.streamlit/': No such file or directory
failed to solve with frontend dockerfile.v0: failed to build LLB: executor failed running [/bin/sh -c cp .streamlit/ ~/.streamlit/config.toml]: runc did not terminate sucessfully

This is my folder structure.

I also tried moving .streamlit folder to same location of the Dockerfile. But it didn’t work for me.

I also tried the other workarounds suggested in the community by changing docker file CMD to

streamlit run --server.enableCORS=false
streamlit run --server.enableWebsocketCompression=false

But still getting the same error.

502 Bad Gateway


FROM python:3.7


COPY ./requirements.txt /requirements.txt

RUN pip install --trusted-host --trusted-host --trusted-host -r /requirements.txt

COPY ./app /app


# streamlit-specific commands

#RUN mkdir ~/.streamlit

#RUN cp .streamlit/ ~/.streamlit/config.toml


CMD streamlit run --server.enableWebsocketCompression=false

Can someone help me where Exactly I am missing.


I am able to fix the issue. Here is the solution if someone face similar issue.
Use :
COPY .streamlit/ /root/.streamlit/config.toml
instead of
RUN cp .streamlit/ ~/.streamlit/config.toml

This solved the issue. The application perfectly works on Azure platform.

Hi Chakra,

your folder structure looks not correct, you are trying to copy the folder outside of build context, you can move your .streamlit folder to inside your docker build context.