This document is relevant for: Inf1

DLC sample Dockerfile for Application Container#

  1FROM ubuntu:18.04
  2
  3#SDK 1.17.1 has version 1. We skipped 1.18.0.
  4LABEL dlc_major_version="2"
  5LABEL maintainer="Amazon AI"
  6LABEL com.amazonaws.sagemaker.capabilities.accept-bind-to-port=true
  7
  8ARG PYTHON=python3.7
  9ARG PYTHON_VERSION=3.7.10
 10ARG TS_VERSION=0.5.2
 11ARG MAMBA_VERSION=4.12.0-0
 12
 13# See http://bugs.python.org/issue19846
 14ENV LANG C.UTF-8
 15ENV LD_LIBRARY_PATH /lib/x86_64-linux-gnu:/opt/conda/lib/:$LD_LIBRARY_PATH
 16ENV PATH /opt/conda/bin:$PATH
 17ENV SAGEMAKER_SERVING_MODULE sagemaker_pytorch_serving_container.serving:main
 18ENV TEMP=/home/model-server/tmp
 19
 20RUN apt-get update \
 21 && apt-get install -y --no-install-recommends software-properties-common \
 22 && add-apt-repository ppa:openjdk-r/ppa \
 23 && apt-get update \
 24 && apt-get install -y --no-install-recommends \
 25    build-essential \
 26    apt-transport-https \
 27    ca-certificates \
 28    cmake \
 29    curl \
 30    emacs \
 31    git \
 32    jq \
 33    libgl1-mesa-glx \
 34    libglib2.0-0 \
 35    libsm6 \
 36    libxext6 \
 37    libxrender-dev \
 38    openjdk-11-jdk \
 39    vim \
 40    wget \
 41    unzip \
 42    zlib1g-dev \
 43    libcap-dev \
 44    gpg-agent \
 45 && rm -rf /var/lib/apt/lists/* \
 46 && rm -rf /tmp/tmp* \
 47 && apt-get clean
 48
 49RUN echo "deb https://apt.repos.neuron.amazonaws.com bionic main" > /etc/apt/sources.list.d/neuron.list
 50RUN wget -qO - https://apt.repos.neuron.amazonaws.com/GPG-PUB-KEY-AMAZON-AWS-NEURON.PUB | apt-key add -
 51
 52RUN apt-get update \
 53 && apt-get install -y \
 54    aws-neuron-tools \
 55 && rm -rf /var/lib/apt/lists/* \
 56 && rm -rf /tmp/tmp* \
 57 && apt-get clean
 58
 59
 60# https://github.com/docker-library/openjdk/issues/261 https://github.com/docker-library/openjdk/pull/263/files
 61RUN keytool -importkeystore -srckeystore /etc/ssl/certs/java/cacerts -destkeystore /etc/ssl/certs/java/cacerts.jks -deststoretype JKS -srcstorepass changeit -deststorepass changeit -noprompt; \
 62    mv /etc/ssl/certs/java/cacerts.jks /etc/ssl/certs/java/cacerts; \
 63    /var/lib/dpkg/info/ca-certificates-java.postinst configure;
 64
 65RUN curl -L -o ~/mambaforge.sh https://github.com/conda-forge/miniforge/releases/download/${MAMBA_VERSION}/Mambaforge-${MAMBA_VERSION}-Linux-x86_64.sh \
 66 && chmod +x ~/mambaforge.sh \
 67 && ~/mambaforge.sh -b -p /opt/conda \
 68 && rm ~/mambaforge.sh \
 69 && /opt/conda/bin/conda update conda \
 70 && /opt/conda/bin/conda install -c conda-forge -y \
 71    python=$PYTHON_VERSION \
 72    cython \
 73    mkl-include \
 74    mkl \
 75    parso \
 76    scipy \
 77    typing \
 78    # Below 2 are included in miniconda base, but not mamba so need to install
 79    conda-content-trust \
 80    charset-normalizer \
 81 && /opt/conda/bin/conda clean -ya
 82
 83RUN conda install -c conda-forge \
 84    opencv \
 85    scikit-learn \
 86    pandas \
 87    h5py \
 88    requests \
 89 && conda clean -ya \
 90 && pip install --upgrade pip --trusted-host pypi.org --trusted-host files.pythonhosted.org \
 91 && ln -s /opt/conda/bin/pip /usr/local/bin/pip3 \
 92 && pip install packaging==20.4 \
 93    enum-compat==0.0.3 \
 94    numpy==1.20.3 \
 95    ipython \
 96    # pyOpenSSL requires cryptography>=2.3, but all versions <3.3 have vulnerabilities
 97    "cryptography>=3.3.2"
 98
 99RUN pip install --no-cache-dir -U \
100    scipy \
101    six \
102    # install PyYAML>=5.4 to avoid conflict with latest awscli
103    "pyYAML>=5.4,<5.5" \
104    "pillow>=8.3" \
105    "awscli<2" \
106    boto3
107
108RUN pip install neuron-cc[tensorflow] --extra-index-url https://pip.repos.neuron.amazonaws.com \
109 && pip install "torch-neuron>=1.10.2,<1.10.3" --extra-index-url https://pip.repos.neuron.amazonaws.com \
110 && pip install torchserve==$TS_VERSION \
111 && pip install --no-deps --no-cache-dir -U torchvision==0.11.3 \
112 # Install TF 1.15.5 to override neuron-cc[tensorflow]'s installation of tensorflow==1.15.0
113 && pip install -U tensorflow==1.15.5 \
114 && pip install torch-model-archiver==$TS_VERSION
115
116RUN useradd -m model-server \
117 && mkdir -p /home/model-server/tmp /opt/ml/model \
118 && chown -R model-server /home/model-server /opt/ml/model
119
120COPY torchserve-neuron.sh /usr/local/bin/entrypoint.sh
121COPY config.properties /home/model-server
122
123RUN chmod +x /usr/local/bin/dockerd-entrypoint.py \
124 && chmod +x /usr/local/bin/neuron-monitor.sh \
125 && chmod +x /usr/local/bin/entrypoint.sh
126
127ADD https://raw.githubusercontent.com/aws/deep-learning-containers/master/src/deep_learning_container.py /usr/local/bin/deep_learning_container.py
128
129RUN chmod +x /usr/local/bin/deep_learning_container.py
130
131RUN pip install --no-cache-dir "sagemaker-pytorch-inference==2.0.8"
132
133RUN HOME_DIR=/root \
134 && curl -o ${HOME_DIR}/oss_compliance.zip https://aws-dlinfra-utilities.s3.amazonaws.com/oss_compliance.zip \
135 && unzip ${HOME_DIR}/oss_compliance.zip -d ${HOME_DIR}/ \
136 && cp ${HOME_DIR}/oss_compliance/test/testOSSCompliance /usr/local/bin/testOSSCompliance \
137 && chmod +x /usr/local/bin/testOSSCompliance \
138 && chmod +x ${HOME_DIR}/oss_compliance/generate_oss_compliance.sh \
139 && ${HOME_DIR}/oss_compliance/generate_oss_compliance.sh ${HOME_DIR} ${PYTHON} \
140 && rm -rf ${HOME_DIR}/oss_compliance*
141
142RUN curl https://aws-dlc-licenses.s3.amazonaws.com/pytorch-1.10/license.txt -o /license.txt
143
144EXPOSE 8080 8081
145
146CMD ["/usr/local/bin/entrypoint.sh"]

This document is relevant for: Inf1