Dockerfile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # Build tflow cause they suck with version support
  2. # Define base image, pin at buster
  3. FROM debian:10.4-slim as builder
  4. LABEL maintainer="tarfeef101"
  5. SHELL ["/bin/bash", "-c"]
  6. # Install required packages, etc
  7. RUN apt -y update && \
  8. apt -y upgrade && \
  9. apt -y install curl wget git bzip2 unzip python3 python-dev python-pip python3-dev python3-pip pkg-config zip g++ zlib1g-dev && \
  10. apt purge && \
  11. apt clean && \
  12. rm -rf /var/lib/apt/lists/*
  13. ENV LANG C.UTF-8
  14. # Install pip packages
  15. RUN python -m pip install -U pip six numpy wheel setuptools mock 'future>=0.17.1' && \
  16. python -m pip install -U keras_applications>=1.0.8 --no-deps && \
  17. python -m pip install -U keras_preprocessing>=1.1.0 --no-deps && \
  18. python -m pip install -U absl-py>=0.7.0 astor>=0.6.0 'backports.weakref>=1.0rc1;python_version<"3.4"' 'enum34>=1.1.6;python_version<"3.4"' \
  19. gast==0.2.2 google_pasta>=0.1.6 'numpy>=1.16.0,<2.0' opt_einsum>=2.3.2 protobuf>=3.8.0 'tensorboard>=2.1.0,<2.2.0' \
  20. 'tensorflow_estimator>=2.1.0rc0,<2.2.0' termcolor>=1.1.0 wrapt>=1.11.1 'functools32>=3.2.3;python_version<"3"' scipy==1.2.2
  21. # install cuda
  22. RUN apt update && \
  23. apt -y install ca-certificates apt-transport-https gnupg2 && \
  24. rm -rf /var/lib/apt/lists/* && \
  25. curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub | apt-key add - && \
  26. echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list && \
  27. echo "deb https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/nvidia-ml.list
  28. ENV CUDA_VERSION 10.1.243
  29. ENV CUDA_PKG_VERSION 10-1=$CUDA_VERSION-1
  30. RUN apt-get update && apt-get install -y --no-install-recommends \
  31. cuda-cudart-$CUDA_PKG_VERSION \
  32. cuda-compat-10-1 && \
  33. ln -s cuda-10.1 /usr/local/cuda && \
  34. rm -rf /var/lib/apt/lists/*
  35. LABEL com.nvidia.volumes.needed="nvidia_driver"
  36. LABEL com.nvidia.cuda.version="${CUDA_VERSION}"
  37. RUN echo "/usr/local/nvidia/lib" >> /etc/ld.so.conf.d/nvidia.conf && \
  38. echo "/usr/local/nvidia/lib64" >> /etc/ld.so.conf.d/nvidia.conf
  39. ENV PATH /usr/local/nvidia/bin:/usr/local/cuda/bin:${PATH}
  40. ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64
  41. ENV NVIDIA_VISIBLE_DEVICES all
  42. ENV NVIDIA_DRIVER_CAPABILITIES all
  43. ENV NVIDIA_REQUIRE_CUDA "cuda>=10.1"
  44. ENV NCCL_VERSION 2.4.8
  45. RUN apt-get update && apt-get install -y --no-install-recommends \
  46. cuda-libraries-$CUDA_PKG_VERSION \
  47. cuda-nvtx-$CUDA_PKG_VERSION \
  48. libcublas10=10.2.1.243-1 \
  49. libnccl2=$NCCL_VERSION-1+cuda10.1
  50. RUN apt-get update && apt-get install -y --no-install-recommends \
  51. cuda-nvml-dev-$CUDA_PKG_VERSION \
  52. cuda-command-line-tools-$CUDA_PKG_VERSION \
  53. cuda-libraries-dev-$CUDA_PKG_VERSION \
  54. cuda-minimal-build-$CUDA_PKG_VERSION \
  55. libnccl-dev=$NCCL_VERSION-1+cuda10.1 \
  56. libcublas-dev=10.2.1.243-1 && \
  57. rm -rf /var/lib/apt/lists/*
  58. ENV LIBRARY_PATH /usr/local/cuda/lib64/stubs
  59. ENV CUDNN_VERSION 7.6.5.32
  60. LABEL com.nvidia.cudnn.version="${CUDNN_VERSION}"
  61. RUN apt-get update && apt-get install -y --no-install-recommends \
  62. libcudnn7=$CUDNN_VERSION-1+cuda10.1 \
  63. libcudnn7-dev=$CUDNN_VERSION-1+cuda10.1 && \
  64. rm -rf /var/lib/apt/lists/*
  65. RUN apt-get update && apt-get install -y --no-install-recommends \
  66. libnvinfer6=6.0.1-1+cuda10.1 \
  67. libnvinfer-dev=6.0.1-1+cuda10.1 \
  68. libnvinfer-plugin6=6.0.1-1+cuda10.1 \
  69. libnvinfer-plugin-dev=6.0.1-1+cuda10.1
  70. # install Bazel
  71. RUN wget https://github.com/bazelbuild/bazel/releases/download/0.29.1/bazel-0.29.1-installer-linux-x86_64.sh && \
  72. chmod +x bazel-0.29.1-installer-linux-x86_64.sh && \
  73. ./bazel-0.29.1-installer-linux-x86_64.sh --user
  74. # Get/build tflow
  75. RUN cd /opt && \
  76. git clone https://github.com/tensorflow/tensorflow.git && \
  77. cd tensorflow && \
  78. git checkout r2.1
  79. RUN export PATH=$PATH:/root/bin && \
  80. export TF_NEED_CUDA=1 && \
  81. export TF_NEED_TENSORRT=1 && \
  82. export TF_CUDA_VERSION=10.1 && \
  83. export TF_CUDNN_VERSION=7.6.5 && \
  84. export TF_CUBLAS_VERSION=10.2.1 && \
  85. export TF_NCCL_VERSION=2.4.8 && \
  86. export TF_TENSORRT_VERSION=6 && \
  87. export TF_CUDA_PATHS=/usr/local/cuda,/usr/lib/x86_64-linux-gnu,/usr&& \
  88. cd /opt/tensorflow && \
  89. ./configure && \
  90. bazel build tensorflow/tools/pip_package:build_pip_package
  91. RUN export PATH=$PATH:/root/bin && \
  92. cd /opt/tensorflow && \
  93. ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /opt && \
  94. ls /opt
  95. # Copy just installer to reduce image size drastically
  96. FROM scratch
  97. COPY --from=builder /opt/tensorflow-2.1.1-cp27-cp27mu-linux_x86_64.whl /opt/tensorflow-2.1.1-cp27-cp27mu-linux_x86_64.whl