-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
457 lines (392 loc) · 14.5 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# Stage 1: Build OpenCV with CUDA
FROM nvidia/cuda:12.4.0-devel-ubuntu22.04 AS builder
# Set environment variables to minimize interactive prompts and set locale
ENV DEBIAN_FRONTEND=noninteractive \
LANG=C.UTF-8 \
OPENCV_VERSION=4.10.0
# Install build dependencies, upgrade pip, download, and extract OpenCV in one `RUN` to minimize layers
RUN apt-get update && \
apt-get install --allow-change-held-packages -y --no-install-recommends \
wget build-essential gcc-10 g++-10 cmake git unzip pkg-config libjpeg-dev libpng-dev libtiff-dev \
libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libgtk-3-dev \
libatlas-base-dev gfortran libgl1 python3-dev python3-pip espeak-ng libespeak-ng1 && \
python3 -m pip install --upgrade --no-cache-dir pip numpy && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ; \
mkdir -p /opt/opencv_build && cd /opt/opencv_build && \
wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
unzip opencv.zip && unzip opencv_contrib.zip && \
rm opencv.zip opencv_contrib.zip && \
mv opencv-${OPENCV_VERSION} opencv && mv opencv_contrib-${OPENCV_VERSION} opencv_contrib && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Create build directory
WORKDIR /opt/opencv_build/opencv/build
# Configure OpenCV with CUDA and set GCC/G++ 10
RUN cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_C_COMPILER=gcc-10 \
-D CMAKE_CXX_COMPILER=g++-10 \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=/opt/opencv_build/opencv_contrib/modules \
-D WITH_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_EXAMPLES=OFF \
-D WITH_GSTREAMER=ON \
-D WITH_LIBV4L=ON \
# Disable QT to save space
-D WITH_QT=OFF \
-D WITH_OPENGL=ON \
-D BUILD_opencv_python3=ON \
-D BUILD_TESTS=OFF \
..
# Build and install OpenCV
RUN make -j4 && make install && ldconfig && make clean && \
rm -rf /opt/opencv_build/opencv && rm -rf /opt/opencv_build/opencv_contrib && \
apt-get purge -y --auto-remove \
wget \
build-essential \
gcc-10 \
g++-10 \
cmake \
git \
unzip \
pkg-config \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libv4l-dev \
libxvidcore-dev \
libx264-dev \
libgtk-3-dev \
libatlas-base-dev \
gfortran \
libgl1 \
python3-dev \
python3-pip \
espeak-ng \
libespeak-ng1 \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Stage 2: Create the final image
FROM nvidia/cuda:12.4.0-runtime-ubuntu22.04
# Set environment variables to minimize interactive prompts and set locale
ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8
# Install runtime dependencies
RUN apt-get update && apt-get install --allow-change-held-packages -y --no-install-recommends \
libnvidia-ml-dev \
libcudnn9-cuda-12 \
libcudnn9-dev-cuda-12 \
cuda-toolkit-12-4 \
libcublas-12-4 \
libcublas-dev-12-4 \
python3-dev \
python3-pip \
espeak-ng \
libespeak-ng1 \
&& rm -rf /var/lib/apt/lists/*
# Upgrade pip and install runtime Python dependencies
RUN python3 -m pip install --upgrade pip
# Copy OpenCV from the builder stage
COPY --from=builder /usr/local /usr/local
# Verify OpenCV installation
RUN python3 -c "import cv2; print('OpenCV Version:', cv2.__version__)" && \
python3 -c "import cv2; print('CUDA Enabled Devices:', cv2.cuda.getCudaEnabledDeviceCount())"
# Create a working directory for the application
WORKDIR /app
# Copy your application code into the container
COPY . /app
# Install repository requirements
RUN pip install --no-cache-dir -r requirements.txt
# Install YOLOv8 and other Python dependencies
RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
# Define the entrypoint or command
CMD ["python3", "yolov8_live_rtmp_stream_detection.py", "--headless"]
# // old versions, to be deleted //
# # Stage 1: Build OpenCV with CUDA
# FROM nvidia/cuda:12.4.0-devel-ubuntu22.04 AS builder
# # Set environment variables to minimize interactive prompts and set locale
# ENV DEBIAN_FRONTEND=noninteractive
# ENV LANG=C.UTF-8
# # Install build dependencies and CUDA libraries
# RUN apt-get update && apt-get install --allow-change-held-packages -y --no-install-recommends \
# wget \
# build-essential \
# gcc-10 g++-10 \
# cmake \
# git \
# unzip \
# pkg-config \
# libjpeg-dev \
# libpng-dev \
# libtiff-dev \
# libavcodec-dev \
# libavformat-dev \
# libswscale-dev \
# libv4l-dev \
# libxvidcore-dev \
# libx264-dev \
# libgtk-3-dev \
# libatlas-base-dev \
# gfortran \
# libgl1 \
# python3-dev \
# python3-pip \
# espeak-ng \
# libespeak-ng1 \
# && rm -rf /var/lib/apt/lists/*
# # Upgrade pip and install Python dependencies needed for building OpenCV
# RUN python3 -m pip install --upgrade pip numpy
# # Define OpenCV version
# ENV OPENCV_VERSION=4.10.0
# # Create a directory for OpenCV
# WORKDIR /opt/opencv_build
# # Download OpenCV and OpenCV_contrib
# RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
# wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
# unzip opencv.zip && unzip opencv_contrib.zip && \
# rm opencv.zip opencv_contrib.zip && \
# mv opencv-${OPENCV_VERSION} opencv && mv opencv_contrib-${OPENCV_VERSION} opencv_contrib
# # Create build directory
# WORKDIR /opt/opencv_build/opencv/build
# # Configure OpenCV with CUDA and set GCC/G++ 10
# RUN cmake -D CMAKE_BUILD_TYPE=RELEASE \
# -D CMAKE_C_COMPILER=gcc-10 \
# -D CMAKE_CXX_COMPILER=g++-10 \
# -D CMAKE_INSTALL_PREFIX=/usr/local \
# -D OPENCV_EXTRA_MODULES_PATH=/opt/opencv_build/opencv_contrib/modules \
# -D WITH_CUDA=ON \
# -D ENABLE_FAST_MATH=1 \
# -D CUDA_FAST_MATH=1 \
# -D WITH_CUBLAS=1 \
# -D OPENCV_ENABLE_NONFREE=ON \
# -D BUILD_EXAMPLES=OFF \
# -D WITH_GSTREAMER=ON \
# -D WITH_LIBV4L=ON \
# -D WITH_QT=OFF \
# -D WITH_OPENGL=ON \
# -D BUILD_opencv_python3=ON \
# -D BUILD_TESTS=OFF \
# ..
# # Build and install OpenCV
# RUN make -j4 && make install && ldconfig && make clean && \
# rm -rf /opt/opencv_build/opencv && rm -rf /opt/opencv_build/opencv_contrib && \
# apt-get purge -y --auto-remove \
# wget \
# build-essential \
# gcc-10 \
# g++-10 \
# cmake \
# git \
# unzip \
# pkg-config \
# libjpeg-dev \
# libpng-dev \
# libtiff-dev \
# libavcodec-dev \
# libavformat-dev \
# libswscale-dev \
# libv4l-dev \
# libxvidcore-dev \
# libx264-dev \
# libgtk-3-dev \
# libatlas-base-dev \
# gfortran \
# libgl1 \
# python3-dev \
# python3-pip \
# espeak-ng \
# libespeak-ng1 \
# && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# # Stage 2: Create the final image
# FROM nvidia/cuda:12.4.0-runtime-ubuntu22.04
# # Set environment variables to minimize interactive prompts and set locale
# ENV DEBIAN_FRONTEND=noninteractive
# ENV LANG=C.UTF-8
# # Install runtime dependencies
# RUN apt-get update && apt-get install --allow-change-held-packages -y --no-install-recommends \
# libnvidia-ml-dev \
# libcudnn9-cuda-12 \
# libcudnn9-dev-cuda-12 \
# cuda-toolkit-12-4 \
# libcublas-12-4 \
# libcublas-dev-12-4 \
# python3-dev \
# python3-pip \
# espeak-ng \
# libespeak-ng1 \
# && rm -rf /var/lib/apt/lists/*
# # Upgrade pip and install runtime Python dependencies
# RUN python3 -m pip install --upgrade pip
# # Copy OpenCV from the builder stage
# COPY --from=builder /usr/local /usr/local
# # Verify OpenCV installation
# RUN python3 -c "import cv2; print('OpenCV Version:', cv2.__version__)" && \
# python3 -c "import cv2; print('CUDA Enabled Devices:', cv2.cuda.getCudaEnabledDeviceCount())"
# # Create a working directory for the application
# WORKDIR /app
# # Copy your application code into the container
# COPY . /app
# # Install repository requirements
# RUN pip install --no-cache-dir -r requirements.txt
# # Install YOLOv8 and other Python dependencies
# RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
# # Define the entrypoint or command
# CMD ["python3", "yolov8_live_rtmp_stream_detection.py", "--headless"]
# // these methods run out of disk space at GitHub
# # Use NVIDIA CUDA base image with Ubuntu 22.04
# # FROM nvidia/cuda:12.4.0-base-ubuntu22.04
# # FROM nvidia/cuda:12.4.0-runtime-ubuntu22.04
# FROM nvidia/cuda:12.4.0-runtime-ubuntu22.04
# # Set environment variables
# ENV DEBIAN_FRONTEND=noninteractive
# ENV LANG=C.UTF-8
# # nvidia-cuda-toolkit \
# # Add NVIDIA’s repo key and set up the proper repository for the latest CUDA versions
# # Get `wget` first
# RUN apt-get update && apt-get install -y --no-install-recommends wget
# # Add NVIDIA’s repo key and set up the repository for the latest CUDA versions
# RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb && \
# dpkg -i cuda-keyring_1.0-1_all.deb && \
# apt-get update && \
# apt-get install -y --no-install-recommends \
# --allow-change-held-packages \
# libnvidia-ml-dev \
# gcc-10 g++-10 \
# build-essential \
# libcudnn9-cuda-12=9.1.* \
# libcudnn9-dev-cuda-12=9.1.* \
# cuda-toolkit-12-4=12.4.* \
# libcublas-12-4=12.4.5.* \
# libcublas-dev-12-4=12.4.5.* \
# cmake \
# git \
# wget \
# unzip \
# pkg-config \
# libjpeg-dev \
# libpng-dev \
# libtiff-dev \
# libavcodec-dev \
# libavformat-dev \
# libswscale-dev \
# libv4l-dev \
# libxvidcore-dev \
# libx264-dev \
# libgtk-3-dev \
# libatlas-base-dev \
# gfortran \
# libgl1 \
# python3-dev \
# python3-pip \
# espeak-ng \
# libespeak-ng1 \
# && rm -rf /var/lib/apt/lists/*
# # # Then, run the keyring in
# # RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb && \
# # dpkg -i cuda-keyring_1.0-1_all.deb && \
# # apt-get update
# # # Install system dependencies
# # RUN apt-get update && apt-get install -y --no-install-recommends \
# # nvidia-cuda-dev \
# # nvidia-cuda-gdb \
# # gcc-10 g++-10 \
# # build-essential \
# # libcudnn9-cuda-12 \
# # libcudnn9-dev-cuda-12 \
# # cuda-toolkit-12-4 \
# # cmake \
# # git \
# # wget \
# # unzip \
# # pkg-config \
# # libjpeg-dev \
# # libpng-dev \
# # libtiff-dev \
# # libavcodec-dev \
# # libavformat-dev \
# # libswscale-dev \
# # libv4l-dev \
# # libxvidcore-dev \
# # libx264-dev \
# # libgtk-3-dev \
# # libatlas-base-dev \
# # gfortran \
# # libgl1 \
# # python3-dev \
# # python3-pip \
# # espeak-ng \
# # libespeak-ng1 \
# # && rm -rf /var/lib/apt/lists/*
# # apt-clean
# RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# # Upgrade pip for Python 3.12
# RUN python3 -m pip install --upgrade pip
# # Install Python dependencies
# RUN python3 -m pip install --no-cache-dir numpy
# # Define OpenCV version
# ENV OPENCV_VERSION=4.10.0
# # Create a directory for OpenCV
# WORKDIR /opt/opencv_build
# # Download OpenCV and OpenCV_contrib
# RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
# wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
# unzip opencv.zip && unzip opencv_contrib.zip && \
# rm opencv.zip opencv_contrib.zip && \
# mv opencv-${OPENCV_VERSION} opencv && mv opencv_contrib-${OPENCV_VERSION} opencv_contrib
# # Create build directory
# WORKDIR /opt/opencv_build/opencv/build
# # Configure OpenCV with CUDA and set GCC/G++ 10
# RUN cmake -D CMAKE_BUILD_TYPE=RELEASE \
# -D CMAKE_C_COMPILER=gcc-10 \
# -D CMAKE_CXX_COMPILER=g++-10 \
# -D CMAKE_INSTALL_PREFIX=/usr/local \
# -D OPENCV_EXTRA_MODULES_PATH=/opt/opencv_build/opencv_contrib/modules \
# -D WITH_CUDA=ON \
# -D ENABLE_FAST_MATH=1 \
# -D CUDA_FAST_MATH=1 \
# -D WITH_CUBLAS=1 \
# -D OPENCV_ENABLE_NONFREE=ON \
# -D BUILD_EXAMPLES=OFF \
# -D WITH_GSTREAMER=ON \
# -D WITH_LIBV4L=ON \
# -D WITH_QT=ON \
# -D WITH_OPENGL=ON \
# -D BUILD_opencv_python3=ON \
# -D BUILD_TESTS=OFF \
# ..
# # Build OpenCV
# RUN make -j$(nproc)
# RUN make install
# RUN rm -rf /opt/opencv_build
# RUN ldconfig
# RUN python3 -m pip install --upgrade pip
# # Install YOLOv8 and other Python dependencies
# RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
# # Verify OpenCV installation and CUDA support in a single RUN command
# RUN echo "==============================================================" && \
# echo "If OpenCV compilation was successful, it should show up below:" && \
# echo "==============================================================" && \
# python3 -c "import cv2; print('OpenCV Version:', cv2.__version__)" && \
# python3 -c "import cv2; print('CUDA Enabled Devices:', cv2.cuda.getCudaEnabledDeviceCount())" && \
# echo "==============================================================" && \
# echo "Verification completed at $(date)"
# # Create a working directory for the application
# WORKDIR /app
# # Copy your application code into the container
# COPY . /app
# # install repository requirements
# RUN pip install --no-cache-dir -r requirements.txt
# # Expose any necessary ports (if applicable)
# # Example: EXPOSE 8000
# # Define the entrypoint or command
# # Run the detection with GUI (requires x11docker or a X11 passthrough method!)
# # CMD ["python3", "yolov8_live_rtmp_stream_detection.py"]
# # Run headless (unless you're configuring X11 passthrough, this might be easier)
# CMD ["python3", "yolov8_live_rtmp_stream_detection.py", "--headless"]