/ tests / resources / dockerfile / Dockerfile_sagemaker_virtualenv
Dockerfile_sagemaker_virtualenv
 1  # Build an image that can serve mlflow models.
 2  FROM ubuntu:22.04
 3  
 4  RUN apt-get -y update && DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get install -y --no-install-recommends wget curl nginx ca-certificates bzip2 build-essential cmake git-core
 5  
 6  # Setup pyenv
 7  RUN DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC apt-get -y install tzdata \
 8      libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
 9      libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
10  RUN git clone \
11      --depth 1 \
12      --branch $(git ls-remote --tags --sort=v:refname https://github.com/pyenv/pyenv.git | grep -o -E 'v[1-9]+(\.[1-9]+)+$' | tail -1) \
13      https://github.com/pyenv/pyenv.git /root/.pyenv
14  ENV PYENV_ROOT="/root/.pyenv"
15  ENV PATH="$PYENV_ROOT/bin:$PATH"
16  RUN apt install -y software-properties-common \
17      && apt update \
18      && add-apt-repository -y ppa:deadsnakes/ppa \
19      && apt update \
20      && apt install -y python3.10 python3.10-distutils \
21      # Remove python3-blinker to avoid pip uninstall conflicts
22      && apt remove -y python3-blinker \
23      && ln -s -f $(which python3.10) /usr/bin/python \
24      && wget https://bootstrap.pypa.io/get-pip.py -O /tmp/get-pip.py \
25      && python /tmp/get-pip.py
26  
27  
28  # Setup Java
29  RUN apt-get install -y --no-install-recommends openjdk-17-jdk maven
30  ENV JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
31  
32  WORKDIR /opt/mlflow
33  
34  # Install MLflow from local source
35  COPY mlflow-project /opt/mlflow
36  RUN pip install /opt/mlflow
37  
38  # Install minimal serving dependencies
39  RUN python -c "from mlflow.models.container import _install_pyfunc_deps;_install_pyfunc_deps(None, False)"
40  
41  ENV MLFLOW_DISABLE_ENV_CREATION=False
42  ENV ENABLE_MLSERVER=False
43  
44  # granting read/write access and conditional execution authority to all child directories
45  # and files to allow for deployment to AWS Sagemaker Serverless Endpoints
46  # (see https://docs.aws.amazon.com/sagemaker/latest/dg/serverless-endpoints.html)
47  RUN chmod o+rwX /opt/mlflow/
48  
49  # clean up apt cache to reduce image size
50  RUN rm -rf /var/lib/apt/lists/*
51  
52  ENTRYPOINT ["python", "-c", "import sys; from mlflow.models import container as C; C._init(sys.argv[1], 'virtualenv')"]