-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
39 lines (29 loc) · 952 Bytes
/
Dockerfile
File metadata and controls
39 lines (29 loc) · 952 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
# Multi-stage build
FROM python:3.12-slim AS builder
WORKDIR /app
# Install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Runtime stage
FROM python:3.12-slim
# Create non-root user
RUN useradd -m appuser
USER appuser
WORKDIR /app
USER root
RUN apt-get update && \
apt-get install -y git nginx && \
rm -rf /var/lib/apt/lists/*
USER appuser
# Copy from builder
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy app code
COPY . .
# Expose port
EXPOSE 8085
# Healthcheck: use python to avoid installing curl in slim image
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python3 -c "import urllib.request; urllib.request.urlopen('http://localhost:8085/')" || exit 1
# Run as non-root
CMD ["uvicorn", "api.server:app", "--host", "0.0.0.0", "--port", "8080"]