-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
34 lines (24 loc) · 950 Bytes
/
Dockerfile
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 AS builder
# Set working directory in the container
WORKDIR /app
# Copy only requirements to leverage Docker layer caching
COPY requirements.txt .
# Create a virtual environment and activate it
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Install project dependencies within the virtual environment
RUN pip install --no-cache-dir -r requirements.txt
# Stage 2: Production Stage
FROM python:3.11-slim
# Set working directory in the container
WORKDIR /app
# Copy only necessary files from the builder stage, including the virtual environment
COPY --from=builder /opt/venv /opt/venv
COPY . .
# Set the environment variable to use the virtual environment
ENV PATH="/opt/venv/bin:$PATH"
# Expose the port where the FastAPI app will run
EXPOSE 8080
# Command to run the FastAPI app using Uvicorn or other ASGI servers
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]