Streamlit - Docker App

Hello, I'm testing how to deploy a Python Streamlit app using docker. I have tested locally and it works, however I'm having an issue where I cannot access the actual website. This is my docker file:
FROM python:3.9-slim-bullseye

ARG PORT

WORKDIR /app

RUN apt-get update && apt-get install -y \
build-essential \
curl \
software-properties-common \
git \
&& rm -rf /var/lib/apt/lists/*

COPY . .

RUN pip3 install -r requirements.txt

EXPOSE $PORT

HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health

ENTRYPOINT ["streamlit", "run", "app.py","--server.port=$PORT","--server.address=0.0.0.0"]
FROM python:3.9-slim-bullseye

ARG PORT

WORKDIR /app

RUN apt-get update && apt-get install -y \
build-essential \
curl \
software-properties-common \
git \
&& rm -rf /var/lib/apt/lists/*

COPY . .

RUN pip3 install -r requirements.txt

EXPOSE $PORT

HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health

ENTRYPOINT ["streamlit", "run", "app.py","--server.port=$PORT","--server.address=0.0.0.0"]
I have set the $PORT variable in railway. It deploys sucessfully but when it's trying to excecute the streamlit app it gives me this error:
Error: Invalid value for '--server.port': '$PORT' is not a valid integer.

Usage: streamlit run [OPTIONS] TARGET [ARGS]...
Error: Invalid value for '--server.port': '$PORT' is not a valid integer.

Usage: streamlit run [OPTIONS] TARGET [ARGS]...
Solution:
remove the ENTRYPOINT line and replace it with
CMD streamlit run app.py --server.address 0.0.0.0 --server.port $PORT --server.fileWatcherType none --browser.gatherUsageStats false --client.showErrorDetails false --client.toolbarMode minimal
CMD streamlit run app.py --server.address 0.0.0.0 --server.port $PORT --server.fileWatcherType none --browser.gatherUsageStats false --client.showErrorDetails false --client.toolbarMode minimal
read more about this command and all its flags here https://github.com/brody192/streamlit-hello?tab=readme-ov-file#what-makes-this-work-on-railway...
Jump to solution
11 Replies
Percy
Percy10mo ago
Project ID: N/A
ottog.eth
ottog.ethOP10mo ago
PROJECT ID: 84cb72e2-0b70-4a72-9763-be101ea3eaca Project ID: 84cb72e2-0b70-4a72-9763-be101ea3eaca
Brody
Brody10mo ago
please use tripple backticks for these code blocks
ottog.eth
ottog.ethOP10mo ago
Done! thanks for catching that
Solution
Brody
Brody10mo ago
remove the ENTRYPOINT line and replace it with
CMD streamlit run app.py --server.address 0.0.0.0 --server.port $PORT --server.fileWatcherType none --browser.gatherUsageStats false --client.showErrorDetails false --client.toolbarMode minimal
CMD streamlit run app.py --server.address 0.0.0.0 --server.port $PORT --server.fileWatcherType none --browser.gatherUsageStats false --client.showErrorDetails false --client.toolbarMode minimal
read more about this command and all its flags here https://github.com/brody192/streamlit-hello?tab=readme-ov-file#what-makes-this-work-on-railway
ottog.eth
ottog.ethOP10mo ago
Thanks! I tried that and it now builds. However, when I try to access it it https://streamlittest-production.up.railway.app:8501, it never loads
ottog.eth
ottog.ethOP10mo ago
Thank you so much! this is working now! just as a curiosity, why the entry point line in my docker file wasn't working?
Brody
Brody10mo ago
that was ran in exec mode, so the environment variable $PORT wasn't be escaped to it's set value and thus the literal string $PORT was being passed into the streamlit cli
ottog.eth
ottog.ethOP10mo ago
I see... Thank you so much for your help @Brody !
Brody
Brody10mo ago
no problem!
Want results from more Discord servers?
Add your server