-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
41 lines (29 loc) · 1014 Bytes
/
Copy pathDockerfile
File metadata and controls
41 lines (29 loc) · 1014 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
37
38
39
40
41
# ---------------------------
# Stage 1 - Builder
# ---------------------------
FROM python:3.11-slim AS builder
WORKDIR /app
# Install build dependencies (for compiling C extensions if needed)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential gcc libffi-dev \
&& rm -rf /var/lib/apt/lists/*
# Copy dependencies list
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# ---------------------------
# Stage 2 - Final runtime image
# ---------------------------
FROM python:3.11-slim
WORKDIR /app
# Security best practice: create non-root user
RUN useradd -m appuser
USER appuser
# Copy installed dependencies from builder stage
COPY --from=builder /usr/local /usr/local
# Copy application code
COPY . .
# Expose application port
EXPOSE 5000
# Run application with Gunicorn (production server)
CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:5000", "--workers", "3", "--timeout", "120", "--log-level", "info"]