

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 清除映像資源
<a name="rstudio-byoi-sdk-cleanup"></a>

本指南說明如何清理您在上一節中建立的 RStudio 映像資源。若要刪除映像，請使用 SageMaker AI 主控台或 完成下列步驟 AWS CLI，如本指南所示。
+ 從您的 Amazon SageMaker AI 網域中分離映像和映像版本。
+ 刪除映像，映像版本和應用程式映像組態。

完成這些步驟後，您可以從 Amazon ECR 刪除容器映像和儲存庫。如需如何刪除容器映像和儲存庫的更多詳細資訊，請參閱[刪除儲存庫](https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-delete.html)。

## 從 SageMaker AI 主控台清除資源
<a name="rstudio-byoi-sdk-cleanup-console"></a>

當您從區域中分離映像時，會分離映像的所有版本。分離映像後，網域的所有使用者都會失去對映像版本的存取權。

**若要分離映像**

1. 開啟 Amazon SageMaker AI 主控台，網址為 [https://console.aws.amazon.com/sagemaker/](https://console.aws.amazon.com/sagemaker/)。

1. 在左側導覽窗格中，選擇**管理員組態**。

1. 在**管理員組態**下，選擇**網域**。

1. 選取所需的網域。

1. 選擇**環境**。

1. 在**連接至網域的自訂映像**下，選擇映像，然後選擇**分離**。

1. (選用) 若要從 SageMaker AI 刪除映像和所有版本，請選取**同時刪除選取的映像…**。這不會從 Amazon ECR 中刪除相關聯的映像。

1. 請選擇**分離**。

## 從 清除資源 AWS CLI
<a name="rstudio-byoi-sdk-cleanup-cli"></a>

**清理資源**

1. 透過將空白的自訂映像清單傳送至網域，從網域中分離映像和映像版本。開啟您建立於 [將 SageMaker 映像連接到您目前的網域](studio-byoi-attach.md#studio-byoi-sdk-attach-current-domain) 的 `update-domain-input.json` 檔案。

1. 刪除 `RSessionAppSettings` 自訂映像，然後儲存檔案。請勿修改 `KernelGatewayAppSettings` 自訂映像。

   ```
   {
       "DomainId": "d-xxxxxxxxxxxx",
       "DefaultUserSettings": {
         "KernelGatewayAppSettings": {
            "CustomImages": [
            ],
            ...
         },
         "RSessionAppSettings": { 
           "CustomImages": [ 
           ],
           "DefaultResourceSpec": { 
           }
           ...
         }
       }
   }
   ```

1. 使用網域 ID 和預設使用者設定檔案來更新您的網域。

   ```
   aws sagemaker update-domain \
       --domain-id {{<d-xxxxxxxxxxxx>}} \
       --cli-input-json file://update-domain-input.json
   ```

   回應：

   ```
   {
       "DomainArn": "arn:aws:sagemaker:us-east-2:acct-id:domain/d-xxxxxxxxxxxx"
   }
   ```

1. 刪除應用程式映像組態。

   ```
   aws sagemaker delete-app-image-config \
       --app-image-config-name rstudio-image-config
   ```

1. 刪除 SageMaker 映像，此映像也會刪除所有映像版本。Amazon ECR 中以映像版本顯示的容器映像不會被刪除。

   ```
   aws sagemaker delete-image \
       --image-name rstudio-image
   ```