-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
36 lines (25 loc) · 925 Bytes
/
Dockerfile
File metadata and controls
36 lines (25 loc) · 925 Bytes
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
### Stage 1: Build environment with dependencies ###
FROM python:3.12-alpine AS builder
WORKDIR /app
# Install build tools for packages with native extensions
RUN apk add --no-cache build-base
# Copy and install dependencies into user-local path
COPY requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt
# Copy application source code
COPY . .
### Stage 2: Minimal runtime image ###
FROM python:3.12-alpine
# Create a non-root user
RUN adduser -D appuser
WORKDIR /app
# Copy application and installed dependencies from builder stage
COPY --from=builder /app /app
COPY --from=builder /root/.local /home/appuser/.local
# Set correct PATH so that user-installed packages are found
ENV PATH=/home/appuser/.local/bin:$PATH
# Create a data directory and set permissions
RUN mkdir -p /app/data && chown -R appuser /app /home/appuser
# Switch to non-root user
USER appuser
CMD ["python", "run.py"]