Update Dockerfile
Browse files- Dockerfile +22 -8
Dockerfile
CHANGED
|
@@ -2,7 +2,7 @@ FROM python:3.9-slim
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
# Install system dependencies
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
build-essential \
|
| 8 |
curl \
|
|
@@ -11,19 +11,33 @@ RUN apt-get update && apt-get install -y \
|
|
| 11 |
libgl1 \
|
| 12 |
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
-
ENV HOME=/app
|
| 17 |
-
ENV XDG_CONFIG_HOME=/app/.config
|
| 18 |
-
|
| 19 |
COPY requirements.txt ./
|
| 20 |
COPY src/ ./src/
|
| 21 |
|
| 22 |
-
# Install Python dependencies
|
| 23 |
RUN pip3 install --no-cache-dir -r requirements.txt
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
EXPOSE 8501
|
| 26 |
|
| 27 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
|
| 28 |
|
| 29 |
-
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Install system dependencies
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
build-essential \
|
| 8 |
curl \
|
|
|
|
| 11 |
libgl1 \
|
| 12 |
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
|
| 14 |
+
# Copy requirements and source code BEFORE creating the non-root user
|
| 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 |
+
# --- Create a non-root user and grant permissions ---
|
| 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 |
+
# Switch to the non-root user
|
| 31 |
+
USER appuser
|
| 32 |
+
# --- End of user creation section ---
|
| 33 |
+
|
| 34 |
+
# You no longer need these lines as chown handles permissions for the entire /app directory
|
| 35 |
+
# RUN mkdir -p /app/.streamlit /app/.config
|
| 36 |
+
# ENV HOME=/app
|
| 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 |
+
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|