Dockerfile specifications - Amazon SageMaker

Dockerfile specifications

The image that you specify in your Dockerfile must match the specifications in the following sections to create the image successfully.

Running the image

  • Entrypoint – We recommend embedding the entry point into the image using the Docker CMD or Entrypoint instructions. You can also configure ContainerEntrypoint and ContainerArguments that are passed to the container at runtime. For more information, see CodeEditorAppImageConfig.

  • EnvVariables – With Studio, you can configure ContainerEnvironment variables that are made available to a container. The environment variable is overwritten with the environment variables from SageMaker. To provide you with a better experience, the environment variables are usually AWS_ and SageMaker_namespaced to give priority to platform environments.

    The following are the environment variables:

    • AWS_REGION

    • AWS_DEFAULT_REGION

    • AWS_CONTAINER_CREDENTIALS_RELATIVE_URI

    • SAGEMAKER_SPACE_NAME

Specifications for the user and file system

  • WorkingDirectory – The Amazon EBS volume for your space is mounted on the path /home/sagemaker-user. You can't change the mount path. Use the WORKDIR instruction to set the working directory of your image to a folder within /home/sagemaker-user.

  • UID – The user ID of the Docker container. UID=1000 is a supported value. You can add sudo access to your users. The IDs are remapped to prevent a process running in the container from having more privileges than necessary.

  • GID – The group ID of the Docker container. GID=100 is a supported value. You can add sudo access to your users. The IDs are remapped to prevent a process running in the container from having more privileges than necessary.

  • Meta data directories – The /opt/.sagemakerinternal and /opt/ml directories that are used by AWS. The meta data file in /opt/ml contains meta data about resources such as DomainId.

    Use the following command to show the file system contents:

    cat /opt/ml/metadata/resource-metadata.json {"AppType":"CodeEditor","DomainId":"example-domain-id","UserProfileName":"example-user-profile-name,"ResourceArn":"arn:aws:sagemaker:AWS Region:111122223333;:app/domain-ID/user-ID/CodeEditor/default","ResourceName":"default","AppImageVersion":"current"}
  • Logging directories – /var/log/studio are reserved for the logging directories of Code Editor and the extensions associated with it. We recommend that you don't use the folders in creating your image.

Health check and URL for applications

  • Base URL – The base URL for the BYOI application must be codeeditor/default. You can only have one application and it must always be named default.

  • Health check endpoint – You must host your Code Editor server at 0.0.0.0 port 8888 for SageMaker to detect it.

  • Authentication – You must pass --without-connection-token when opening sagemaker-code-editor to allow SageMaker to authenticate your users.

Note

If you are using Amazon SageMaker Distribution as the base image, these requirements are already taken care of as part of the included entrypoint-code-editor script.

Dockerfile samples

The following is a sample Dockerfile that meets the specifications listed in the previous sections to create an image from scratch using a micromamba base environment:

FROM mambaorg/micromamba:latest ARG NB_USER="sagemaker-user" ARG NB_UID=1000 ARG NB_GID=100 USER root RUN micromamba install -y --name base -c conda-forge sagemaker-code-editor USER $NB_UID CMD eval "$(micromamba shell hook --shell=bash)"; \ micromamba activate base; \ sagemaker-code-editor --host 0.0.0.0 --port 8888 \ --without-connection-token \ --base-path "/CodeEditor/default"

The following is a sample Dockerfile that meets the specifications listed in the previous sections to create an image based on Amazon SageMaker Distribution:

FROM public.ecr.aws/sagemaker/sagemaker-distribution:latest-cpu ARG NB_USER="sagemaker-user" ARG NB_UID=1000 ARG NB_GID=100 ENV MAMBA_USER=$NB_USER USER root # install scrapy in the base environment RUN micromamba install -y --name base -c conda-forge scrapy # download VSCodeVim RUN \ wget https://github.com/VSCodeVim/Vim/releases/download/v1.27.2/vim-1.27.2.vsix \ -P /tmp/exts/ --no-check-certificate # Install the extension RUN \ extensionloc=/opt/amazon/sagemaker/sagemaker-code-editor-server-data/extensions \ && sagemaker-code-editor \ --install-extension "/tmp/exts/vim-1.27.2.vsix" \ --extensions-dir "${extensionloc}" USER $MAMBA_USER ENTRYPOINT ["entrypoint-code-editor"]