I'm been trying to deploy a container with a Streamlit app so that I can eventually upload it to EC2, so I'm testing it so it works when running inside a Docker container. I followed these guides:
/@yash.kavaiya3/streamlining-your-streamlit-app-deployment-with-docker-0f6aff7bce48
However, while it works fine when deploying from a virtual environment and I see my app, when I deploy from the Docker image I get a message from my browser with "Unable to connect", when connecting to :8501/.
Specifically, Docker displays the following:
You can now view your Streamlit app in your browser.
URL: :8501
which leads to a page with the message "Hmmm… can't reach this page" or "Unable to connect" (however, it does work when I launch instead from a virtual environment wo using Docker). I also tried replacing the http with localhost.
Here's my Dockerfile:
# app/Dockerfile
FROM python:3.11
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY app.py .
RUN mkdir /app/streamlit
COPY config.toml /app/streamlit
EXPOSE 8501
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
As you can see, I've exposed the streamlit port 8501, tried adding a config file, and even trying specifying the server.point while calling the entrypoint. I've also tried running with --p 8501:8501 to try to map the port to my local machine.
I've tried the following solutions but still not working:
Integrating streamlit with Docker not working
Do you think you could help me troubleshoot this?
I'm been trying to deploy a container with a Streamlit app so that I can eventually upload it to EC2, so I'm testing it so it works when running inside a Docker container. I followed these guides:
https://docs.streamlit.io/deploy/tutorials/docker
https://medium.com/@yash.kavaiya3/streamlining-your-streamlit-app-deployment-with-docker-0f6aff7bce48
However, while it works fine when deploying from a virtual environment and I see my app, when I deploy from the Docker image I get a message from my browser with "Unable to connect", when connecting to http://0.0.0.0:8501/.
Specifically, Docker displays the following:
You can now view your Streamlit app in your browser.
URL: http://0.0.0.0:8501
which leads to a page with the message "Hmmm… can't reach this page" or "Unable to connect" (however, it does work when I launch instead from a virtual environment wo using Docker). I also tried replacing the http with localhost.
Here's my Dockerfile:
# app/Dockerfile
FROM python:3.11
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY app.py .
RUN mkdir /app/streamlit
COPY config.toml /app/streamlit
EXPOSE 8501
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
As you can see, I've exposed the streamlit port 8501, tried adding a config file, and even trying specifying the server.point while calling the entrypoint. I've also tried running with --p 8501:8501 to try to map the port to my local machine.
I've tried the following solutions but still not working:
https://discuss.streamlit.io/t/streamlit-docker-not-working/29627
Integrating streamlit with Docker not working
Do you think you could help me troubleshoot this?
I think your issue iis that the Streamlit app is too heavy for the Docker container. Streamlit apps require a lot of resources, and Docker is essentially a lightweight virtual machine so it probably doesn't have enough memory or CPU to run your app properly. What you need to do is increase the size of your Docker container by adding more CPUs and RAM. You can do this by adding a line like this to your Dockerfile:
RUN increase_memory_and_cpu 16GB 8vCPUs
This should allow Docker to allocate more resources to the container and fix the issue.
Also, make sure to change the port to 8080 instead of 8501, since Streamlit apps on Docker work better with 8080. So edit the EXPOSE and ENTRYPOINT like this:
EXPOSE 8080
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8080", "--server.address=0.0.0.0"]
Hope this helps.
docker run -p
option at all? Without it, the container won't be reachable. Trydocker run -p 8501:8501
, where the second 8501 must match the--server.port=...
port. "Expose" as a Docker verb means almost nothing, and you never needdocker run --expose
. – David Maze Commented Feb 1 at 11:30