-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (38 loc) · 1.25 KB
/
Dockerfile
File metadata and controls
51 lines (38 loc) · 1.25 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Use official Python runtime as base image
FROM python:3.11-slim-bullseye AS builder
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1
# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
python3-dev && \
rm -rf /var/lib/apt/lists/*
# Create and set working directory
WORKDIR /app
# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# --- Runtime stage ---
FROM python:3.11-slim-bullseye
# Install runtime dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libgomp1 && \
rm -rf /var/lib/apt/lists/*
# Copy dependencies
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Make sure uvicorn (and any other pip-installed CLI tools) are on the PATH
ENV PATH="/usr/local/bin:${PATH}"
# Create non-root user and app directory
RUN useradd -m appuser && \
mkdir -p /app && \
chown -R appuser /app
WORKDIR /app
COPY --chown=appuser . .
USER appuser
EXPOSE 8000
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]