Update Dockerfile
Browse files- Dockerfile +20 -6
Dockerfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# Stage 1:
|
2 |
FROM python:3.10-slim AS builder
|
3 |
|
4 |
# Install system dependencies
|
@@ -6,30 +6,44 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
6 |
build-essential \
|
7 |
&& rm -rf /var/lib/apt/lists/*
|
8 |
|
9 |
-
# Set
|
|
|
|
|
|
|
10 |
WORKDIR /app
|
11 |
|
12 |
-
# Copy the requirements file first for caching
|
13 |
COPY requirements.txt /app/
|
14 |
|
15 |
-
# Install dependencies
|
16 |
RUN pip install --no-cache-dir --upgrade pip
|
17 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
18 |
|
19 |
# Stage 2: Production
|
20 |
FROM python:3.10-slim
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
# Set environment variables for user installation
|
23 |
ENV PATH=/root/.local/bin:$PATH
|
24 |
ENV PYTHONUNBUFFERED=1
|
|
|
25 |
|
26 |
# Set the working directory in the container
|
27 |
WORKDIR /app
|
28 |
|
29 |
-
# Copy
|
30 |
COPY --from=builder /root/.local /root/.local
|
|
|
|
|
31 |
COPY . /app
|
32 |
|
|
|
|
|
|
|
33 |
# Expose the port that the FastAPI app runs on
|
34 |
EXPOSE 8001
|
35 |
|
|
|
1 |
+
# Stage 1: Builder
|
2 |
FROM python:3.10-slim AS builder
|
3 |
|
4 |
# Install system dependencies
|
|
|
6 |
build-essential \
|
7 |
&& rm -rf /var/lib/apt/lists/*
|
8 |
|
9 |
+
# Set environment variables for user installation
|
10 |
+
ENV PATH=/root/.local/bin:$PATH
|
11 |
+
|
12 |
+
# Set the working directory in the builder
|
13 |
WORKDIR /app
|
14 |
|
15 |
+
# Copy the requirements file first for better caching
|
16 |
COPY requirements.txt /app/
|
17 |
|
18 |
+
# Install dependencies to /root/.local using --user
|
19 |
RUN pip install --no-cache-dir --upgrade pip
|
20 |
+
RUN pip install --no-cache-dir --user -r requirements.txt
|
21 |
|
22 |
# Stage 2: Production
|
23 |
FROM python:3.10-slim
|
24 |
|
25 |
+
# Install system dependencies
|
26 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
27 |
+
libpq-dev \
|
28 |
+
&& rm -rf /var/lib/apt/lists/*
|
29 |
+
|
30 |
# Set environment variables for user installation
|
31 |
ENV PATH=/root/.local/bin:$PATH
|
32 |
ENV PYTHONUNBUFFERED=1
|
33 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
34 |
|
35 |
# Set the working directory in the container
|
36 |
WORKDIR /app
|
37 |
|
38 |
+
# Copy installed Python packages from the builder stage
|
39 |
COPY --from=builder /root/.local /root/.local
|
40 |
+
|
41 |
+
# Copy the current directory contents into the container
|
42 |
COPY . /app
|
43 |
|
44 |
+
# Ensure that the Python path includes the local packages
|
45 |
+
ENV PYTHONPATH=/root/.local/lib/python3.10/site-packages:$PYTHONPATH
|
46 |
+
|
47 |
# Expose the port that the FastAPI app runs on
|
48 |
EXPOSE 8001
|
49 |
|