Connection time out on streamlit app on accessing url through docker container

I am using a dockerfile like:

FROM python:3.7.3

WORKDIR /app

COPY requirements.txt /app/

RUN pip install --no-cache-dir -r requirements.txt
RUN pip install streamlit

COPY . /app

EXPOSE 8501

CMD ["streamlit", "run", "app.py"]

and on running the docker image:
docker run -d -p 8051:8080 --name app firstimage:v1

I get a message in the logs of the container:


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


  You can now view your Streamlit app in your browser.

  URL: http://0.0.0.0:8501

On accessing the URL through my browser, I get timed out after a while. Do you know how to fix this?

Thank you very much!

It seems like you are facing connectivity issues when trying to access your Streamlit app running inside a Docker container. Here are a few things you can check and try to resolve the issue:

Port Mapping:

In your docker run command, you have -p 8051:8080, which maps port 8080 from the container to port 8051 on the host. However, your Streamlit app is running on port 8501 inside the container (CMD [“streamlit”, “run”, “app.py”]). Ensure that you are mapping the correct port.
Update your docker run command to:

docker run -d -p 8501:8501 --name app firstimage:v1

This will map port 8501 from the container to port 8501 on the host.

Check Firewall Settings:

Make sure that there are no firewall restrictions preventing external access to port 8501 on your host machine. Adjust your firewall settings if needed.
Binding to All Network Interfaces:

By default, Streamlit binds to localhost (0.0.0.0) inside the Docker container. This should allow external access. However, you might want to explicitly specify the host when running the Streamlit app:
Update your CMD in the Dockerfile to:


CMD ["streamlit", "run", "--server.address", "0.0.0.0", "app.py"]

Check Docker Container Logs:

Check the logs of your Docker container to see if there are any error messages or issues reported. You can use the following command to view container logs:
bash

docker logs app

Replace “app” with the actual name of your running container.

Docker Container IP:

In some cases, you might need to use the IP address of the Docker container instead of 0.0.0.0 when accessing the app. You can find the container’s IP address using:

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' app

Replace “app” with the actual name of your running container.

After making these adjustments, try accessing your Streamlit app using the correct URL (http://localhost:8501) or (http://<container_ip>:8501) in your browser. If the issue persists, check the logs for any error messages that might provide more information about the problem.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.