Skip to content

Commit ad1ec85

Browse files
committed
feat: add multi-stage Dockerfile for building and running app
1 parent 5e194dd commit ad1ec85

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Stage 1: Build
2+
FROM python:3.12-slim-bookworm AS build
3+
4+
WORKDIR /app
5+
6+
COPY requirements.txt .
7+
RUN pip install --no-cache-dir -r requirements.txt
8+
9+
COPY . .
10+
11+
# Stage 2: Runtime
12+
FROM python:3.12-slim-bookworm AS runtime
13+
14+
WORKDIR /app
15+
16+
COPY requirements.txt .
17+
RUN pip install --no-cache-dir -r requirements.txt
18+
19+
COPY models ./models
20+
COPY routes ./routes
21+
COPY schemas ./schemas
22+
COPY services ./services
23+
COPY data ./data
24+
COPY main.py .
25+
26+
# Add non-root 'fastapi' user (optional for hardening)
27+
RUN adduser --disabled-password --gecos '' fastapi \
28+
&& chown -R fastapi:fastapi /app
29+
USER fastapi
30+
31+
EXPOSE 9000
32+
ENV PYTHONUNBUFFERED=1
33+
34+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "9000"]

0 commit comments

Comments
 (0)