-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile
More file actions
42 lines (32 loc) · 1.21 KB
/
Copy pathdockerfile
File metadata and controls
42 lines (32 loc) · 1.21 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
# syntax=docker/dockerfile:1
FROM python:3.11-slim
# 1. Set environment variables for Python and FastAPI
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
DEBIAN_FRONTEND=noninteractive
WORKDIR /app
# 2. Install system dependencies
RUN --mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt/lists \
rm -f /etc/apt/apt.conf.d/docker-clean && \
apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
sox \
libsox-fmt-all \
git
# 3. Copy only requirements first (better layer caching)
COPY requirements.txt .
# RUN --mount=type=cache,target=/root/.cache/pip \
# pip install torch --index-url https://download.pytorch.org/whl/cu121 && \
# grep -v "^torch" requirements.txt | pip install -r /dev/stdin
# 4. Install Python dependencies
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements.txt
# 5. Create a non-root user for security (crucial for cloud deployments)
RUN adduser --disabled-password --gecos '' appuser
USER appuser
# 6. Copy the rest of the application code
COPY --chown=appuser:appuser . .
EXPOSE 8000
# 7. Use the exec form for CMD
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]