-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
65 lines (51 loc) · 1.89 KB
/
Dockerfile
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Build stage
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04 AS builder
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /app
# Install system dependencies and Python 3.8
RUN apt-get update && apt-get install -y --no-install-recommends \
libopencv-dev \
build-essential \
libffi-dev \
libssl-dev \
python3.8 \
python3.8-dev \
python3-pip \
python3-setuptools \
libcairo2-dev \
libgirepository1.0-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# Upgrade pip and setuptools, install Python dependencies
COPY requirements.txt requirements-dev.txt /app/
RUN python3.8 -m pip install --no-cache-dir --upgrade pip setuptools wheel && \
python3.8 -m pip install --no-cache-dir -r requirements.txt -r requirements-dev.txt
# Install PyTorch with CUDA support in the build stage
RUN python3.8 -m pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# Copy the application code and install the project
COPY . /app
RUN python3.8 -m pip install --no-cache-dir .
# Final stage
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu20.04
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive
ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
WORKDIR /app
# Install only the necessary runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libopencv-dev \
python3.8 \
python3-pip \
libcairo2 \
libgirepository1.0-dev \
pkg-config \
&& rm -rf /var/lib/apt/lists/*
# Copy installed Python packages and application files from the builder
COPY --from=builder /usr/local/lib/python3.8/ /usr/local/lib/python3.8/
COPY --from=builder /app /app
# Create necessary directories
RUN mkdir -p /app/data /app/models /app/logs
EXPOSE 8080
ENTRYPOINT ["python3.8", "run.py"]