Dockerfile 4.4 KB

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