-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (32 loc) · 1.18 KB
/
Dockerfile
File metadata and controls
47 lines (32 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# --- Build Stage ---
FROM python:3.12-slim AS builder
# Create a virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:${PATH}"
WORKDIR /app
# --- Install Dependencies ---
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# --- Copy the rest of the application
COPY . .
RUN python run.py
# --- Final Stage ---
FROM python:3.12-slim
WORKDIR /app
# --- Create a non-root user WITH a home directory ---
RUN groupadd --system appgroup && useradd --system --create-home --gid appgroup appuser
# Copy the perfected virtual environment from the builder
COPY --from=builder /opt/venv /opt/venv
# --- Copy only the necessary files from the builder stage
COPY --from=builder /app/app.py .
COPY --from=builder /app/config.py .
COPY --from=builder /app/.streamlit ./.streamlit/
COPY --from=builder /app/images ./images/
# --- Change ownership of BOTH the app and the venv ---
RUN chown -R appuser:appgroup /app /opt/venv
# -- Switch to the non-root user
USER appuser
# Activate the virtual environment for the final image
ENV PATH="/opt/venv/bin:${PATH}"
EXPOSE 8501
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]