Update Dockerfile
Browse files- Dockerfile +17 -22
Dockerfile
CHANGED
|
@@ -2,42 +2,37 @@ FROM python:3.9-slim
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
# Install system dependencies
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
-
|
| 8 |
-
curl \
|
| 9 |
-
software-properties-common \
|
| 10 |
-
git \
|
| 11 |
-
libgl1 \
|
| 12 |
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
|
| 14 |
-
# Copy requirements and
|
| 15 |
-
# to take advantage of Docker layer caching.
|
| 16 |
COPY requirements.txt ./
|
| 17 |
-
COPY src/ ./src/
|
| 18 |
-
|
| 19 |
-
# Install Python dependencies as root
|
| 20 |
RUN pip3 install --no-cache-dir -r requirements.txt
|
| 21 |
|
| 22 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
# Create a group and user
|
| 24 |
RUN groupadd --system appuser && useradd --system --gid appuser appuser
|
| 25 |
|
| 26 |
-
# Change ownership of the app directory to the new user
|
| 27 |
-
# This allows the app to write config/cache files
|
| 28 |
RUN chown -R appuser:appuser /app
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
#
|
| 37 |
-
# ENV XDG_CONFIG_HOME=/app/.config
|
| 38 |
|
| 39 |
EXPOSE 8501
|
| 40 |
|
| 41 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Install system dependencies needed for OpenCV
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
+
libgl1-mesa-glx \
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
|
| 10 |
+
# Copy requirements and install dependencies as root to leverage caching
|
|
|
|
| 11 |
COPY requirements.txt ./
|
|
|
|
|
|
|
|
|
|
| 12 |
RUN pip3 install --no-cache-dir -r requirements.txt
|
| 13 |
|
| 14 |
+
# Copy the application code from your local `src` folder
|
| 15 |
+
# This will copy `src/streamlit_app.py` and `src/best.pt` to the container
|
| 16 |
+
COPY src/ ./src/
|
| 17 |
+
|
| 18 |
+
# --- User and Permission Setup ---
|
| 19 |
# Create a group and user
|
| 20 |
RUN groupadd --system appuser && useradd --system --gid appuser appuser
|
| 21 |
|
| 22 |
+
# Change ownership of the entire app directory to the new user
|
|
|
|
| 23 |
RUN chown -R appuser:appuser /app
|
| 24 |
|
| 25 |
+
# Set the HOME environment variable for the non-root user.
|
| 26 |
+
# This is the crucial fix for the PermissionError.
|
| 27 |
+
ENV HOME=/app
|
| 28 |
|
| 29 |
+
# Switch to the non-root user for security
|
| 30 |
+
USER appuser
|
| 31 |
+
# --- End of User Setup ---
|
|
|
|
| 32 |
|
| 33 |
EXPOSE 8501
|
| 34 |
|
| 35 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
|
| 36 |
|
| 37 |
+
# Run the app and disable telemetry to prevent writing config files
|
| 38 |
+
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0", "--global.gatherUsageStats=false", "--browser.gatherUsageStats=false"]
|