-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
53 lines (38 loc) · 1.12 KB
/
Copy pathDockerfile
File metadata and controls
53 lines (38 loc) · 1.12 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
48
49
50
51
# Stage 1: Builder
FROM python:3.11-slim AS builder
WORKDIR /app
# Install build dependencies
RUN apt-get update && apt-get install -y \
gcc\
libpq-dev \
netcat-openbsd \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies into a local folder
COPY requirements.txt .
RUN pip install --upgrade pip && \
pip install --prefix=/install --no-cache-dir -r requirements.txt
# Stage 2: Production
FROM python:3.11-slim AS production
WORKDIR /app
# Install only runtime dependencies
RUN apt-get update && apt-get install -y \
gcc\
libpq-dev \
netcat-openbsd \
&& rm -rf /var/lib/apt/lists/*
# Copy installed packages from builder stage
COPY --from=builder /install /usr/local
# Create non-root user for security
RUN addgroup --system appgroup && \
adduser --system --ingroup appgroup appuser
# Copy project files
COPY . .
# Create directories for static and media files
RUN mkdir -p /app/staticfiles /app/media && \
chown -R appuser:appgroup /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8000
# Run entrypoint script
ENTRYPOINT ["sh", "/app/docker/entrypoint.sh"]