Update Dockerfile
Browse files- Dockerfile +23 -11
Dockerfile
CHANGED
|
@@ -1,20 +1,32 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
COPY
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
|
|
|
| 16 |
EXPOSE 8501
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
| 1 |
+
# Use lightweight official Python image
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
|
| 4 |
+
# Prevent Python from writing .pyc files and enable buffering
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
+
|
| 8 |
+
# Set working directory inside container
|
| 9 |
WORKDIR /app
|
| 10 |
|
| 11 |
+
# Copy only requirements first (best practice for caching)
|
| 12 |
+
COPY requirements.txt .
|
| 13 |
+
|
| 14 |
+
# Install dependencies (fast & clean)
|
| 15 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 16 |
+
pip install --no-cache-dir -r requirements.txt
|
| 17 |
|
| 18 |
+
# Copy your entire app (code + model files)
|
| 19 |
+
COPY . .
|
| 20 |
|
| 21 |
+
# Create a non-root user (security best practice)
|
| 22 |
+
RUN useradd -m appuser && chown -R appuser:appuser /app
|
| 23 |
+
USER appuser
|
| 24 |
|
| 25 |
+
# Expose Streamlit port
|
| 26 |
EXPOSE 8501
|
| 27 |
|
| 28 |
+
# Health check (optional but recommended)
|
| 29 |
+
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
|
| 30 |
|
| 31 |
+
# Run Streamlit app
|
| 32 |
+
CMD ["streamlit", "run", "mushroom_app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableCORS=false", "--server.enableXsrfProtection=false"]
|