'Integrating streamlit with Docker not working

I am trying to integrate Streamlit with Docker. Means, I am trying to make a container where the python code is using streamlit.

The app.py is:

import streamlit as st

st.title("Hello Streamlit")
st.header("Calculate % Growth")
initial = st.number_input("Initial investment in USD")
yr = st.number_input("Growth Period in years")
growth = st.number_input("Growth Rate in %")
terminal_value = 0
current_val = initial
for year in range(int(yr)):
   current_val += growth * current_val
   terminal_value = current_val

# perform cashflow projections for the next 5 years
st.write(f'Terminal value of {initial} after {yr} years at a growth rate of {growth} is {terminal_value}')

When I run it with streamlit run app.py, it runs perfectly in the localhost.

Now, I have a Dockerfile. It is:

FROM python:3.8
RUN pip install --upgrade pip
# copy project
COPY . . 
RUN pip install -r requirements.txt
EXPOSE 8501
CMD streamlit run app.py

I build the image as:

docker build -t myimage .

The next step is running the container from the image. It is:

docker run  myimage 

It gives this output in the terminal:


  You can now view your Streamlit app in your browser.

  Network URL: http://172.17.0.3:8501
  External URL: http://79.255.36.161:8501

However, when I go to the localhost, it gives "Hmmm... can't reach this page".

I dont know why it is not working. I am new in Docker. I am using a windows machine (although I dont think it is the problem).

Thanks to all.



Solution 1:[1]

Use http://localhost:8501/ instead of http://172.17.0.3:8501

That worked for me...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 alexpdev