-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
38 lines (27 loc) · 1.13 KB
/
Copy pathDockerfile
File metadata and controls
38 lines (27 loc) · 1.13 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
FROM python:3.12-alpine
# Prevent Python from writing .pyc files and buffer stdout for cleaner logs
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Create a non-root user for security compliance (Alpine syntax)
RUN addgroup -S appuser && \
adduser -S appuser -G appuser -D -s /bin/sh
# Install runtime libraries and temporary build tools
RUN apk update && apk upgrade --no-cache && \
apk add --no-cache libpq && \
apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev
COPY requirements.txt .
# Upgrade pip, install dependencies, clear caches, and NUKE package managers
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
pip install --no-cache-dir -r requirements.txt && \
find / -type d -name "ensurepip" -exec rm -rf {} + || true && \
rm -rf /root/.cache/pip && \
pip uninstall -y setuptools wheel pip
# Remove the build tools to shrink the image and reduce attack surface
RUN apk del .build-deps
# Copy with ownership
COPY --chown=appuser:appuser . .
# Drop root privileges
USER appuser
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]