|
| 1 | +FROM nvidia/cuda:9.1-cudnn7-devel-ubuntu16.04 AS nvidia |
| 2 | +FROM continuumio/anaconda3:5.0.1 |
| 3 | + |
| 4 | +# Avoid interactive configuration prompts/dialogs during apt-get. |
| 5 | +ENV DEBIAN_FRONTEND=noninteractive |
| 6 | + |
| 7 | +# This is necessary to for apt to access HTTPS sources |
| 8 | +RUN apt-get update && \ |
| 9 | + apt-get install apt-transport-https |
| 10 | + |
| 11 | +# Cuda support |
| 12 | +COPY --from=nvidia /etc/apt/sources.list.d/cuda.list /etc/apt/sources.list.d/ |
| 13 | +COPY --from=nvidia /etc/apt/sources.list.d/nvidia-ml.list /etc/apt/sources.list.d/ |
| 14 | +COPY --from=nvidia /etc/apt/trusted.gpg /etc/apt/trusted.gpg.d/cuda.gpg |
| 15 | + |
| 16 | +ENV CUDA_VERSION=9.1.85 |
| 17 | +ENV CUDA_PKG_VERSION=9-1=$CUDA_VERSION-1 |
| 18 | +LABEL com.nvidia.volumes.needed="nvidia_driver" |
| 19 | +LABEL com.nvidia.cuda.version="${CUDA_VERSION}" |
| 20 | +ENV PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH} |
| 21 | +# The stub is useful to us both for built-time linking and run-time linking, on CPU-only systems. |
| 22 | +# When intended to be used with actual GPUs, make sure to (besides providing access to the host |
| 23 | +# CUDA user libraries, either manually or through the use of nvidia-docker) exclude them. One |
| 24 | +# convenient way to do so is to obscure its contents by a bind mount: |
| 25 | +# docker run .... -v /non-existing-directory:/usr/local/cuda/lib64/stubs:ro ... |
| 26 | +ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/nvidia/lib64:/usr/local/cuda/lib64:/usr/local/cuda/lib64/stubs" |
| 27 | +ENV NVIDIA_VISIBLE_DEVICES=all |
| 28 | +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility |
| 29 | +ENV NVIDIA_REQUIRE_CUDA="cuda>=9.0" |
| 30 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 31 | + cuda-cudart-$CUDA_PKG_VERSION \ |
| 32 | + cuda-libraries-$CUDA_PKG_VERSION \ |
| 33 | + cuda-libraries-dev-$CUDA_PKG_VERSION \ |
| 34 | + cuda-nvml-dev-$CUDA_PKG_VERSION \ |
| 35 | + cuda-minimal-build-$CUDA_PKG_VERSION \ |
| 36 | + cuda-command-line-tools-$CUDA_PKG_VERSION \ |
| 37 | + libcudnn7=7.0.5.15-1+cuda9.1 \ |
| 38 | + libcudnn7-dev=7.0.5.15-1+cuda9.1 \ |
| 39 | + libnccl2=2.2.12-1+cuda9.1 \ |
| 40 | + libnccl-dev=2.2.12-1+cuda9.1 && \ |
| 41 | + ln -s /usr/local/cuda-9.1 /usr/local/cuda && \ |
| 42 | + ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/cuda/lib64/stubs/libcuda.so.1 && \ |
| 43 | + rm -rf /var/lib/apt/lists/* |
| 44 | + |
| 45 | +# Install bazel |
| 46 | +RUN apt-get update && apt-get install -y python-software-properties zip && \ |
| 47 | + echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list && \ |
| 48 | + echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list && \ |
| 49 | + apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 C857C906 2B90D010 && \ |
| 50 | + apt-get update && \ |
| 51 | + echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \ |
| 52 | + echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections && \ |
| 53 | + apt-get install -y oracle-java8-installer && \ |
| 54 | + echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list && \ |
| 55 | + curl https://bazel.build/bazel-release.pub.gpg | apt-key add - && \ |
| 56 | + apt-get update && apt-get install -y bazel && \ |
| 57 | + apt-get upgrade -y bazel |
| 58 | + |
| 59 | +# Tensorflow doesn't support python 3.7 yet. See https://github.com/tensorflow/tensorflow/issues/20517 |
| 60 | +RUN conda install -y python=3.6.6 && \ |
| 61 | + # Another fix for TF 1.10 https://github.com/tensorflow/tensorflow/issues/21518 |
| 62 | + pip install keras_applications==1.0.4 --no-deps && \ |
| 63 | + pip install keras_preprocessing==1.0.2 --no-deps |
| 64 | + |
| 65 | +# Fetch tensorflow |
| 66 | +RUN cd /usr/local/src && \ |
| 67 | + git clone https://github.com/tensorflow/tensorflow && \ |
| 68 | + cd tensorflow && \ |
| 69 | + git checkout r1.11 |
| 70 | + |
| 71 | +# Create a tensorflow wheel for CPU |
| 72 | +RUN cd /usr/local/src/tensorflow && \ |
| 73 | + cat /dev/null | ./configure && \ |
| 74 | + bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package && \ |
| 75 | + bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_cpu && \ |
| 76 | + bazel clean |
| 77 | + |
| 78 | +# Create a tensorflow wheel for GPU/cuda |
| 79 | +ENV TF_NEED_CUDA=1 |
| 80 | +ENV TF_CUDA_VERSION=9.1 |
| 81 | +ENV TF_CUDA_COMPUTE_CAPABILITIES=3.7,6.0 |
| 82 | +ENV TF_CUDNN_VERSION=7 |
| 83 | +ENV TF_NCCL_VERSION=2 |
| 84 | +ENV NCCL_INSTALL_PATH=/usr/ |
| 85 | + |
| 86 | +RUN cd /usr/local/src/tensorflow && \ |
| 87 | + # TF_NCCL_INSTALL_PATH is used for both libnccl.so.2 and libnccl.h. Make sure they are both accessible from the same directory. |
| 88 | + ln -s /usr/lib/x86_64-linux-gnu/libnccl.so.2 /usr/lib/ && \ |
| 89 | + cat /dev/null | ./configure && \ |
| 90 | + echo "/usr/local/cuda-${TF_CUDA_VERSION}/targets/x86_64-linux/lib/stubs" > /etc/ld.so.conf.d/cuda-stubs.conf && ldconfig && \ |
| 91 | + bazel build --config=opt \ |
| 92 | + --config=cuda \ |
| 93 | + --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \ |
| 94 | + //tensorflow/tools/pip_package:build_pip_package && \ |
| 95 | + rm /etc/ld.so.conf.d/cuda-stubs.conf && ldconfig && \ |
| 96 | + bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_gpu && \ |
| 97 | + bazel clean |
| 98 | + |
| 99 | +# Print out the built .whl files |
| 100 | +RUN ls -R /tmp/tensorflow* |
0 commit comments