-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
105 lines (85 loc) · 3.51 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
# syntax=docker/dockerfile:1
# =============================================================
# Configuration
# =============================================================
ARG UBUNTU_VERSION=20.04
ARG CUDA_MAJOR_VERSION=11.6.2
ARG CUDNN_MAJOR_VERSION=8
ARG PYTHON_VERSION=3.8.13
ARG PYTORCH_VERSION=1.12.1
ARG TORCHVISION_VERSION=0.13.1
ARG NUMPY_VERSION=1.23.2
ARG BUILD_JOBS=16
# =============================================================
# Create docker
# =============================================================
FROM nvidia/cuda:${CUDA_MAJOR_VERSION}-cudnn${CUDNN_MAJOR_VERSION}-devel-ubuntu${UBUNTU_VERSION} AS base
# propagate build args
ARG CUDA_MAJOR_VERSION
ARG PYTHON_VERSION
ARG PYTORCH_VERSION
ARG TORCHVISION_VERSION
ARG NUMPY_VERSION
ARG BUILD_JOBS
# configure environment variables
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
ENV DEBIAN_FRONTEND noninteractive
# configure timezone
ENV TZ=Europe/Amsterdam
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# install libs
RUN apt-get update --fix-missing && \
apt-get install -y --no-install-recommends \
git \
vim \
screen \
curl \
wget \
xz-utils \
build-essential \
libgomp1 \
libjpeg-turbo8 \
libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev \
libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev gcovr libffi-dev uuid-dev \
libgtk2.0-dev libgsf-1-dev libtiff5-dev libopenslide-dev \
libgl1-mesa-glx libgirepository1.0-dev libexif-dev librsvg2-dev fftw3-dev orc-0.4-dev
# install python with up-to-date pip
RUN cd /tmp && \
wget "https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz" && \
tar xfv Python*.xz && \
cd Python-3*/ && \
./configure --enable-shared LDFLAGS="-fprofile-arcs" && \
make -j${BUILD_JOBS} install && \
cd ~ && \
rm -rf /tmp/Python-3* && \
ldconfig
RUN python3 -m pip install --upgrade pip==24.0 pip-tools wheel setuptools && \
printf '#!/bin/bash\necho "Please use pip3 instead of pip to install packages for python3"' > /usr/local/bin/pip && \
chmod +x /usr/local/bin/pip
# Ensures that Python output to stdout/stderr is not buffered: prevents missing information when terminating
ENV PYTHONUNBUFFERED 1
RUN groupadd -r user && useradd -m --no-log-init -r -g user user
# install python libraries
WORKDIR /opt/app
# create output directory
RUN mkdir /opt/app/data
RUN chown user:user /opt/app/data
COPY --chown=user:user requirements.in /opt/app/
COPY --chown=user:user dataset.py /opt/app/
COPY --chown=user:user loss.py /opt/app/
COPY --chown=user:user utils.py /opt/app/
COPY --chown=user:user segmentation_test_v2.py /opt/app/
COPY --chown=user:user models /opt/app/models
COPY --chown=user:user logs /opt/app/logs
RUN --mount=type=cache,mode=0777,target=/root/.cache/pip cd /opt/app/ && \
CUDA_IDENTIFIER_PYTORCH=`echo "cu${CUDA_MAJOR_VERSION}" | sed "s|\.||g" | cut -c1-5` && \
sed -i \
-e "s|%NUMPY_VERSION%|${NUMPY_VERSION}|g" \
-e "s|%PYTORCH_VERSION%|${PYTORCH_VERSION}+${CUDA_IDENTIFIER_PYTORCH}|g" \
-e "s|%TORCHVISION_VERSION%|${TORCHVISION_VERSION}+${CUDA_IDENTIFIER_PYTORCH}|g" \
requirements.in && \
/usr/local/bin/python3 -m piptools compile requirements.in --verbose --find-links https://download.pytorch.org/whl/torch_stable.html && \
/usr/local/bin/python3 -m piptools sync
USER user
COPY --chown=user:user test.sh /opt/app/
ENTRYPOINT ["bash", "test.sh"]