-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
37 lines (26 loc) · 861 Bytes
/
Dockerfile
File metadata and controls
37 lines (26 loc) · 861 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
# --- Stage 1: Build / Dependencies ---
FROM python:3.10-slim as builder
WORKDIR /app
# Create a non-root user
RUN useradd --create-home appuser
WORKDIR /home/appuser
# Copy only requirements to leverage Docker cache
COPY requirements.txt .
# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
# --- Stage 2: Final Image ---
FROM python:3.10-slim as final
# Create and switch to a non-root user
RUN useradd --create-home appuser
USER appuser
WORKDIR /home/appuser
# Copy installed packages from the builder stage
COPY --from=builder /home/appuser/.local /home/appuser/.local
# Copy the application code
COPY . .
# Set the PATH to include the installed packages
ENV PATH=/home/appuser/.local/bin:$PATH
# Expose the port
EXPOSE 8000
# Command to start the server
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8000"]