-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
36 lines (25 loc) · 830 Bytes
/
Dockerfile
File metadata and controls
36 lines (25 loc) · 830 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
# --- Stage 1: The Builder ---
# We use a full python image to build our dependencies
FROM python:3.9 as builder
WORKDIR /usr/src/app
# Create a virtual environment
RUN python -m venv /opt/venv
# Make sure all commands use the venv
ENV PATH="/opt/venv/bin:"
# Copy and install the requirements
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# --- Stage 2: The Final Image ---
# We use a slim image for a smaller footprint
FROM python:3.9-slim
WORKDIR /usr/src/app
# Copy the virtual environment from the builder stage
COPY --from=builder /opt/venv /opt/venv
# Copy the application code
COPY . .
# Activate the virtual environment
ENV PATH="/opt/venv/bin:"
# Expose the port the app runs on
EXPOSE 8000
# Run the application
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]