This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile_dev
421 lines (359 loc) · 11.3 KB
/
Dockerfile_dev
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
# Dockerfile script to build multi-node training environment.
# (for Tensorflow 1.15.x(compat.v1 & compat.v2) and PyTorch with Horovod)
#
# Author : NoUnique (kofmap@gmail.com)
# Copyright 2020 NoUnique. All Rights Reserved
ARG UBUNTU_VERSION=16.04
ARG CUDA_VERSION=10.0
# Start from the CUDA image
FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION} as base
# UBUNTU_VERSION and CUDA_VERSION are specified again because the FROM directive resets ARGs
# (but their default value is retained if set previously)
ARG UBUNTU_VERSION
ARG CUDA_VERSION
########################################
# Default Settings
########################################
# Needed for string substitution
SHELL ["/bin/bash", "-c"]
# To remove debconf build warnings
ARG DEBIAN_FRONTEND=noninteractive
# (BUGFIX) resolve apt-get signiture verifying problems
RUN chown root:root /tmp; \
chmod 1777 /tmp
# Change locale to fix encoding error on mail-parser install
RUN apt-get update \
&& apt-get install --no-install-suggests -y \
locales \
&& locale-gen en_US.UTF-8 \
&& locale-gen ko_KR.UTF-8 \
;
# Set default locale for the environment
ENV LC_ALL=en_US.UTF-8 \
LANG=ko_KR.UTF-8
# Change the timezone
RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime \
;
# Install essential programs
RUN apt-get update \
&& apt-get install --no-install-suggests -y \
curl \
wget \
unzip \
ssh \
git \
vim \
bc \
;
# Install build tools
RUN apt-get update --fix-missing \
&& apt-get install --no-install-suggests -y \
software-properties-common \
build-essential \
pkg-config \
cmake \
;
####################
# Sudoer
####################
ARG USER
ARG SUDOER=${USER}
# Add sudoer
RUN apt-get install --no-install-suggests -y \
sudo \
&& adduser --disabled-password --gecos '' ${SUDOER} \
&& echo "${SUDOER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${SUDOER} \
&& chmod 0440 /etc/sudoers.d/${SUDOER} \
;
# to access video devices
RUN usermod -aG video ${SUDOER} \
&& usermod -aG audio ${SUDOER} \
;
####################
# Bash
####################
COPY bashrc /etc/bash.bashrc
RUN echo "PS1=(container)\${PS1}">>/home/${USER}/.bashrc
########################################
# Python
########################################
ARG PYTHON_VERSION=3.7.8
ARG USE_PYTHON_3_NOT_2=1
# See http://bugs.python.org/issue19846
#ENV LANG C.UTF-8
ARG _PY_SUFFIX=${USE_PYTHON_3_NOT_2:+3}
ARG PYTHON=python${_PY_SUFFIX}
ARG PIP=pip${_PY_SUFFIX}
# Install python for auto-aliasing
RUN apt-get update \
&& apt-get install --no-install-suggests -y \
${PYTHON} \
${PYTHON}-pip \
;
# Install dependencies
RUN apt-get update --fix-missing \
&& apt-get install --no-install-suggests -y \
zlib1g-dev \
libssl-dev \
libbz2-dev \
libffi-dev \
liblzma-dev \
libreadline-dev \
libsqlite3-dev \
libncurses5-dev \
libncursesw5-dev \
llvm \
tk-dev \
xz-utils \
;
# Install specified version of python
RUN wget -O python.tgz https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz \
&& tar -zxvf python.tgz \
&& rm python.tgz \
&& cd ./Python-${PYTHON_VERSION} \
&& ./configure --enable-shared \
--with-system-expat \
--with-system-ffi \
&& export NPROCS=`cat /proc/cpuinfo | grep cores | wc -l` \
&& make -j ${NPROCS} \
&& make install \
&& ldconfig \
&& cd ../ \
&& rm -rf Python-${PYTHON_VERSION} \
;
# Upgrade pip for auto-aliasing
RUN ${PIP} --no-cache-dir install --upgrade \
pip \
setuptools \
;
# Make symbolic link to python
RUN ln -sf $(which ${PYTHON}) /usr/local/bin/python \
&& ln -sf $(which ${PYTHON}) /usr/bin/python \
&& ln -sf $(which ${PIP}) /usr/local/bin/pip \
&& ln -sf $(which ${PIP}) /usr/bin/pip \
;
########################################
# CUDA & CUDNN
########################################
ARG CUDA_VERSION
ARG CUDNN_VERSION=7.6.2.24-1
# (BUGFIX) nvidia:cuda image overwrite ARG CUDA_VERSION to ENV CUDA_VERSION(with revision version), use CUDA_MINOR_VERSION instead of CUDA_VERSION
RUN CUDA_MINOR_VERSION=${CUDA_VERSION%.*} \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
cuda-command-line-tools-${CUDA_MINOR_VERSION//./-} \
cuda-cublas-${CUDA_MINOR_VERSION//./-} \
cuda-cufft-${CUDA_MINOR_VERSION//./-} \
cuda-curand-${CUDA_MINOR_VERSION/./-} \
cuda-cusolver-${CUDA_MINOR_VERSION//./-} \
cuda-cusparse-${CUDA_MINOR_VERSION//./-} \
libcudnn${CUDNN_VERSION%%.*}=${CUDNN_VERSION}+cuda${CUDA_MINOR_VERSION} \
libcudnn${CUDNN_VERSION%%.*}-dev=${CUDNN_VERSION}+cuda${CUDA_MINOR_VERSION} \
&& apt-mark hold \
libcudnn${CUDNN_VERSION%%.*} \
;
########################################
# FFMpeg
########################################
ARG FFMPEG_VERSION=4.2.2-0york0
# instead of compile it, fetch binary from jonathonf repo
RUN apt-get install --no-install-suggests -y \
software-properties-common \
&& add-apt-repository ppa:jonathonf/ffmpeg-${FFMPEG_VERSION%%.*} \
&& apt-get update \
&& apt-get install --no-install-suggests -y \
ffmpeg \
#ffmpeg=7:${FFMPEG_VERSION}~${UBUNTU_VERSION} \
&& apt-mark hold \
ffmpeg \
;
########################################
# OpenCV
########################################
ARG OPENCV_VERSION=3.4.5
# Install dependencies
# (BUGFIX) to install libjasper-dev package
RUN add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" \
&& apt-get update \
&& apt-get install --no-install-suggests -y \
libgtk2.0-dev libcanberra-gtk-module python3-tk \
libjpeg-dev libtiff5-dev libjasper-dev libpng-dev \
libavcodec-dev libavformat-dev libswscale-dev libavresample-dev \
libxvidcore-dev libx264-dev libxine2-dev \
libv4l-dev v4l-utils \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
mesa-utils libgl1-mesa-dri \
libatlas-base-dev gfortran libeigen3-dev \
python2.7-dev python3-dev python3-numpy \
;
# Install dependencies to build opencv-python
RUN pip install \
numpy \
;
# Build OpenCV3 and it's python bindings
RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip \
&& unzip opencv.zip \
&& rm opencv.zip \
&& wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip \
&& unzip opencv_contrib.zip \
&& rm opencv_contrib.zip \
&& mkdir opencv-${OPENCV_VERSION}/build \
&& cd ./opencv-${OPENCV_VERSION}/build \
&& cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_TBB=OFF \
-D WITH_IPP=OFF \
-D WITH_1394=OFF \
-D BUILD_WITH_DEBUG_INFO=OFF \
-D BUILD_DOCS=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF \
-D WITH_QT=OFF \
-D WITH_GTK2=ON \
-D WITH_OPENGL=ON \
#-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules \
-D WITH_V4L=ON \
-D WITH_FFMPEG=ON \
-D WITH_XINE=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D BUILD_opencv_python3=ON \
-D HAVE_opencv_python3=ON \
-D PYTHON_DEFAULT_EXECUTABLE=$(which ${PYTHON}) \
-D PYTHON3_INCLUDE_DIR=/usr/local/include/python${PYTHON_VERSION%.*}m \
-D PYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python${PYTHON_VERSION%.*}/site-packages/numpy/core/include/ \
-D PYTHON3_PACKAGES_PATH=/usr/local/lib/python${PYTHON_VERSION%.*}/site-packages \
-D PYTHON3_LIBRARY=/usr/local/lib/libpython${PYTHON_VERSION%.*}m.so \
../ \
&& export NPROCS=`cat /proc/cpuinfo | grep cores | wc -l` \
&& make -j ${NPROCS} \
&& make install \
&& cd ../../ \
&& rm -rf opencv-${OPENCV_VERSION} \
&& rm -rf opencv_contrib-${OPENCV_VERSION} \
;
#########################################
# OpenMPI
########################################
ARG OPENMPI_VERSION=4.0.0
# Install OpenMPI
RUN wget -O openmpi.tar.gz https://download.open-mpi.org/release/open-mpi/v${OPENMPI_VERSION:0:3}/openmpi-${OPENMPI_VERSION}.tar.gz \
&& tar -zxvf openmpi.tar.gz \
&& rm openmpi.tar.gz \
&& cd ./openmpi-${OPENMPI_VERSION} \
&& ./configure --enable-orterun-prefix-by-default --with-cuda \
&& export NPROCS=`cat /proc/cpuinfo | grep cores | wc -l` \
&& make -j ${NPROCS} all \
&& make install \
&& ldconfig \
&& cd ../ \
&& rm -rf openmpi-${OPENMPI_VERSION} \
;
#########################################
# NCCL
########################################
# NCCL is already installed in CUDA docker image
#######################################
# Tensorflow
########################################
ARG TENSORFLOW_VERSION=1.15.3
ARG WITH_TFDS=1
# Install Tensorflow (GPU version)
RUN CUDA_MINOR_VERSION=${CUDA_VERSION%.*} \
PYTHON_MINOR_VERSION=${PYTHON_VERSION%.*} \
&& pip --no-cache-dir install \
tensorflow-gpu===${TENSORFLOW_VERSION} \
;
####################
# Tensorflow-Datasets for Tensorflow
####################
ARG TFDS_VERSION=3.2.0
RUN if [ "$WITH_TFDS" = "1" ]; then \
pip --no-cache-dir install \
tensorflow-datasets==${TFDS_VERSION} \
; \
else \
echo "building without tensorflow-datasets" ; \
fi
#######################################
# PyTorch
########################################
ARG PYTORCH_VERSION=1.3.0
ARG WITH_TORCHVISION=1
ARG WITH_TENSORBOARD=1
# Install Pytorch
RUN CUDA_MINOR_VERSION=${CUDA_VERSION%.*} \
PYTHON_MINOR_VERSION=${PYTHON_VERSION%.*} \
&& pip --no-cache-dir install \
torch===${PYTORCH_VERSION}+cu${CUDA_MINOR_VERSION//./} \
-f https://download.pytorch.org/whl/torch_stable.html \
;
####################
# TorchVision for PyTorch
####################
ARG TORCHVISION_VERSION=0.4.1
RUN CUDA_MINOR_VERSION=${CUDA_VERSION%.*} \
PYTHON_MINOR_VERSION=${PYTHON_VERSION%.*} \
&& if [ "$WITH_TORCHVISION" = "1" ]; then \
pip --no-cache-dir install \
torchvision===${TORCHVISION_VERSION}+cu${CUDA_MINOR_VERSION//./} \
-f https://download.pytorch.org/whl/torch_stable.html \
; \
else \
echo "building without torchvision" ; \
fi
####################
# Tensorboard for PyTorch
####################
ARG TENSORBOARD_VERSION=1.15.0
RUN if [ "$WITH_TENSORBOARD" = "1" ]; then \
pip --no-cache-dir install \
#tensorboard==${TENSORBOARD_VERSION} \
tensorboardX \
; \
else \
echo "building without tensorboard" ; \
fi
########################################
# Horovod
########################################
ARG HOROVOD_VERSION=0.18.2
# (BUGFIX) install g++ >= 4.8.5 < 5.0 to build Horovod
RUN apt-get install --no-install-suggests -y \
g++-4.8 \
;
# (BUGFIX) install g++ > 7.3.1 to build horovod with Tensorflow(>=1.15.0)
RUN apt-get install --no-install-suggests -y \
software-properties-common \
&& add-apt-repository ppa:ubuntu-toolchain-r/test \
&& apt-get update \
&& apt-get install --no-install-suggests -y \
g++-7 \
;
# Install Horovod
RUN HOROVOD_GPU_ALLREDUCE=NCCL \
pip --no-cache-dir install \
horovod==${HOROVOD_VERSION} \
;
########################################
# Other dependencies
########################################
# (BUGFIX) install h5py < 3.0.0 to safely load keras model (https://github.com/tensorflow/tensorflow/issues/44467)
RUN pip install \
pillow \
pydub \
h5py==2.10.0 \
keras_preprocessing \
keras_applications \
matplotlib \
numpy \
scipy \
sklearn \
pandas \
future \
thop \
torchsummary \
;