# Use an official Python runtime as a parent image | |
FROM python:3.10-slim | |
# Set the working directory in the container | |
WORKDIR /app | |
# Copy the requirements file into the container at /app | |
COPY requirements.txt . | |
# Install any needed packages specified in requirements.txt | |
# Use --no-cache-dir to reduce layer size and --compile to precompile .py to .pyc | |
RUN pip install --no-cache-dir --compile -r requirements.txt | |
# Copy the rest of the application code into the container at /app | |
COPY . . | |
# Make port 8501 available to the world outside this container (Streamlit default) | |
EXPOSE 8501 | |
# Define environment variable for Streamlit | |
ENV STREAMLIT_SERVER_PORT 8501 | |
ENV STREAMLIT_SERVER_HEADLESS true | |
ENV STREAMLIT_BROWSER_GATHER_USAGE_STATS false | |
# Healthcheck (optional but good for orchestration) | |
# HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health | |
# Run app.py when the container launches | |
# Use `streamlit run app.py` which is the standard way to run Streamlit apps | |
# Add --server.address=0.0.0.0 to make it accessible from outside the container | |
CMD ["streamlit", "run", "app.py", "--server.address=0.0.0.0"] |