Skip to content

Commit 2bc95ed

Browse files
Create Dockerfile-multistage
1 parent 40e9674 commit 2bc95ed

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Dockerfile-multistage

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ------------------- Stage 1: Build Stage ------------------------------
2+
FROM python:3.9 AS builder
3+
4+
WORKDIR /app
5+
6+
# Install build dependencies
7+
RUN apt-get update && \
8+
apt-get install -y --no-install-recommends gcc default-libmysqlclient-dev pkg-config && \
9+
rm -rf /var/lib/apt/lists/*
10+
11+
# Copy and install Python dependencies
12+
COPY requirements.txt .
13+
RUN pip install --no-cache-dir -r requirements.txt
14+
15+
# ------------------- Stage 2: Final Stage ------------------------------
16+
FROM python:3.9-slim
17+
18+
WORKDIR /app
19+
20+
# Install runtime dependencies only
21+
RUN apt-get update && \
22+
apt-get install -y --no-install-recommends libmariadb3 && \
23+
rm -rf /var/lib/apt/lists/*
24+
25+
# Copy dependencies and application code from the builder stage
26+
COPY --from=builder /usr/local/lib/python3.9/site-packages/ /usr/local/lib/python3.9/site-packages/
27+
COPY . .
28+
29+
CMD ["python", "app.py"]

0 commit comments

Comments
 (0)