2

I have a basic streamlit code that I want to run using a dockerfile:

app.py

# app.py
import streamlit as st

def main():
    st.title("Basic Streamlit App")
    
    # Add some text
    st.write("This is a simple Streamlit app.")

    # Add a slider widget
    number = st.slider("Select a number", 1, 100, 50)

    # Display the selected number
    st.write("You selected:", number)

    # Add a button
    if st.button("Click me"):
        st.write("Button clicked!")

    # Add a checkbox
    checkbox_state = st.checkbox("Check me")
    st.write("Checkbox state:", checkbox_state)

    # Add a selectbox
    options = ["Option 1", "Option 2", "Option 3"]
    selected_option = st.selectbox("Select an option", options)
    st.write("You selected:", selected_option)

if __name__ == "__main__":
    main()

Dockerfile

FROM python:3.7

WORKDIR /app

COPY . .

RUN pip3 install -r requirements.txt

EXPOSE 8501

CMD ["streamlit", "run", "app.py", "–server.port=8501", "–server.address=0.0.0.0"]

requirements.txt

streamlit

I run the following commands:

docker build -t streamlit-docker:0.0.1.RELEASE .

docker run -p 8501:8501 streamlit-docker:0.0.1.RELEASE

Collecting usage statistics. To deactivate, set browser.gatherUsageStats to False.


  You can now view your Streamlit app in your browser.

  Network URL: http://172.17.0.4:8501

When I open the URL, the page does not load and returns: This site can’t be reached

I just started with Docker and want to understand where I am going wrong. I tried looking at https://docs.streamlit.io/knowledge-base/tutorials/deploy/docker as well.

EDIT: It works on Mozilla Firefox(122.0.1), but for some reason it does not work when I open the link using Chrome (Version 121.0.6167.184 (Official Build) (arm64))

1
  • I have the same issue unfortunately no solution yet. If I run my app without docker it works Commented Aug 13, 2024 at 11:40

1 Answer 1

1

It looks like your server.address argument is not passed to the streamlit app properly. If you look at the IP address of your app, its deployed to 172.17.0.4 and not 0.0.0.0.

In the CMD line of your Dockerfile, it looks like you are missing a hyphen? This is from the docs: ENTRYPOINT ["streamlit", "run", "streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]

The docs use double hyphens, but your Dockerfile only has one hyphen.

Once the app is deployed to 0.0.0.0, you should be able to access the app at http://0.0.0.0:8501 or http://localhost:8501

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.