

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 更新容器配置
<a name="studio-updated-byoi-how-to-container-configuration"></a>

您可以将自定义 Docker 映像用于机器学习工作流。自定义这些映像的一个关键方面是配置容器配置或 [https://docs.amazonaws.cn/sagemaker/latest/APIReference/API_ContainerConfig.html](https://docs.amazonaws.cn/sagemaker/latest/APIReference/API_ContainerConfig.html)。以下页面提供了有关如何配置 `ContainerConfig` 的示例。

入口点是在容器启动时运行的命令或脚本。利用自定义入口点，您可以在应用程序启动之前设置环境、初始化服务或执行任何必要的设置。

此示例说明如何使用为您的 JupyterLab 应用程序配置自定义入口点。 Amazon CLI此示例假定您已创建一个自定义映像和域。有关说明，请参阅[将自定义映像附加到域](studio-updated-byoi-how-to-attach-to-domain.md)。

1. 首先为接下来的 Amazon CLI 命令设置变量。

   ```
   APP_IMAGE_CONFIG_NAME={{app-image-config-name}}
   ENTRYPOINT_FILE={{entrypoint-file-name}}
   ENV_KEY={{environment-key}}
   ENV_VALUE={{environment-value}}
   REGION={{aws-region}}
   DOMAIN_ID={{domain-id}}
   IMAGE_NAME={{custom-image-name}}
   IMAGE_VERSION={{custom-image-version}}
   ```
   + `{{app-image-config-name}}` 是应用程序映像配置的名称。
   + `{{entrypoint-file-name}}` 是容器入口点脚本的名称。例如 `entrypoint.sh`。
   + `{{environment-key}}` 是环境变量的名称。
   + `{{environment-value}}` 是分配给环境变量的值。
   + `{{aws-region}}`是你 Amazon Web Services 区域 的 Amazon A SageMaker I 域名。你可以在任何 Amazon 主机页面的右上角找到它。
   + `{{domain-id}}` 是域 ID。要查看域，请参阅[查看领域](domain-view.md)。
   + `{{custom-image-name}}` 是自定义映像的名称。要查看自定义映像详细信息，请参阅[查看自定义映像详细信息（控制台）](studio-updated-byoi-view-images.md#studio-updated-byoi-view-images-console)。

     如果您已按照[将自定义映像附加到域](studio-updated-byoi-how-to-attach-to-domain.md)中的说明操作，则可能需要使用该过程中使用的同一映像名称。
   + `{{custom-image-version}}` 是自定义映像的版本号。它应为整数，代表映像的版本。要查看自定义映像详细信息，请参阅[查看自定义映像详细信息（控制台）](studio-updated-byoi-view-images.md#studio-updated-byoi-view-images-console)。

1. 使用 [https://docs.amazonaws.cn/sagemaker/latest/APIReference/API_CreateAppImageConfig.html](https://docs.amazonaws.cn/sagemaker/latest/APIReference/API_CreateAppImageConfig.html) API 创建映像配置。

   ```
   aws sagemaker create-app-image-config \
       --region ${REGION} \
       --app-image-config-name "${APP_IMAGE_CONFIG_NAME}" \
       --jupyter-lab-app-image-config "ContainerConfig = {
           ContainerEntrypoint = "${ENTRYPOINT_FILE}", 
           ContainerEnvironmentVariables = {
               "${ENV_KEY}"="${ENV_VALUE}"
           }
       }"
   ```

1. 使用 [https://docs.amazonaws.cn/sagemaker/latest/APIReference/API_UpdateDomain.html](https://docs.amazonaws.cn/sagemaker/latest/APIReference/API_UpdateDomain.html) API 更新域的默认设置。这将附加自定义映像以及应用程序映像配置。

   ```
   aws sagemaker update-domain \
       --region ${REGION} \
       --domain-id "${DOMAIN_ID}" \
       --default-user-settings "{
           \"JupyterLabAppSettings\": {
               \"CustomImages\": [
                   {
                       \"ImageName\": \"${IMAGE_NAME}\",
                       \"ImageVersionNumber\": ${IMAGE_VERSION},
                       \"AppImageConfigName\": \"${APP_IMAGE_CONFIG_NAME}\"
                   }
               ]
           }
       }"
   ```