-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathDockerfile
More file actions
34 lines (23 loc) · 794 Bytes
/
Dockerfile
File metadata and controls
34 lines (23 loc) · 794 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
# Stage 1: Build stage
FROM python:3.11-slim as builder
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt
# Stage 2: Runtime stage
FROM python:3.11-slim
WORKDIR /app
# Copy only installed packages
COPY --from=builder /root/.local /root/.local
# Create non-root user FIRST
RUN useradd -m -u 1000 appuser
# Copy installed packages to appuser's directory and set permissions
RUN cp -r /root/.local /home/appuser/.local && \
chown -R appuser:appuser /home/appuser/.local
# Set PATH for appuser
ENV PATH=/home/appuser/.local/bin:$PATH
# Copy application code and set ownership
COPY --chown=appuser:appuser ./app ./app
# Switch to non-root user
USER appuser
EXPOSE 8000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]