Streamlit and Docker = Nothing. What am I missing?

I have a very simple app.

/StreamDockerGC

  • main.py
  • Dockerfile
  • requirements.txt

main is very simple (and I tested it, it works)

import streamlit as st

st.write("Hello, world!")

Dockerfile was a bit more complicated, but I was able to build it without issues.

FROM python:3.9

WORKDIR /StreamDockerGC

COPY . .

RUN pip install -r requirements.txt

# Expose Streamlit port
EXPOSE 8501

# Command to run the app
#CMD ["python", ".venv/bin/streamlit", "run", "./main.py"]

ENTRYPOINT ["streamlit", "run", "main.py", "--server.port=8501"]

after building, I am directed to the local and external url.

Both fail and show nothing.

What am I missing?

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

I cleaned up my Dockerfile a bit.

FROM python:3.9-slim

WORKDIR /StreamDockerGC

COPY . .

RUN pip install -r requirements.txt

# Expose Streamlit port
EXPOSE 8501

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

unfortunately, while it BUILDS and I get URLs for the result, the webpage is blank.

When I run JUST the Python file using


streamlit run /home/heinrich/PycharmProjects/StreamDockerGC/main.py

it works fine.

I have used both DockerDesktop and the Terminal and I get the same result.

I am using Fedora 39 (not that it really matters).

Stumped.

Hi @TheBigDuck . You can also create DockerFile as follows:-

FROM python:3.7
WORKDIR /iris-classification
COPY . .
RUN python3 -m pip install -r requirements.txt
RUN python3 source/components/data_loading.py
EXPOSE 9999
ENTRYPOINT ["streamlit","run"]
CMD ["app.py"] 

After building the image, the following command is used for starting the application:-

docker run -p (your_desired_port):8501 tagname:latest

Here I have used 9999 as my desired port.

Hope it helps you in future projects.

Happy Streamlit-ing :balloon:

I edited your suggestion to apply to my project

FROM python:3.9-slim
WORKDIR /StreamDockerGC
COPY . .
RUN pip install -r requirements.txt
#RUN python3 source/components/data_loading.py (doesn't apply to my project)
EXPOSE 8501
ENTRYPOINT ["streamlit","run"]
CMD ["main.py"]

The use of python3 to install the requirements failed on my system.

I still get a blank page.

Maybe I will try Flask and see how that works.

Streamlit doesn’t seem to work.

Hey @TheBigDuck . But that code is working. Have u seen the next command after that? I mean running command??