

終止支援通知： 將於 2026 AWS 年 5 月 20 日結束對 的支援 AWS SimSpace Weaver。2026 年 5 月 20 日之後，您將無法再存取 SimSpace Weaver 主控台或 SimSpace Weaver 資源。如需詳細資訊，請參閱[AWS SimSpace Weaver 終止支援](https://docs.aws.amazon.com/simspaceweaver/latest/userguide/simspaceweaver-end-of-support.html)。

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

# 自訂容器
<a name="working-with_custom-containers"></a>

AWS SimSpace Weaver 應用程式會在容器化 Amazon Linux 2(AL2) 環境中執行。在 中 AWS 雲端， 會在從 Amazon Elastic Container Registry (Amazon ECR) 提供的`amazonlinux:2`映像建置的 Docker 容器中 SimSpace Weaver 執行模擬。您可以建立自訂 Docker 映像檔，將其存放在 Amazon ECR 中，並將該映像檔用於模擬，而不是我們提供的預設 Docker 映像檔。

您可以使用自訂容器來管理您的軟體相依性，並包含不在標準 Docker 映像中的其他軟體元件。例如，您可以將應用程式使用的公開可用的軟體程式庫新增至容器，並只將自訂程式碼放入應用程式 zip 檔案中。

**重要**  
我們僅支援 Amazon ECR 儲存庫中託管的 AL2 Docker 映像，無論是在 Amazon ECR Public Gallery 或您的私有 Amazon ECR 登錄檔中。我們不支援在 Amazon ECR 外部託管的 Docker 映像。如需 Amazon ECR 的詳細資訊，請參閱 *[Amazon Elastic Container Registry 文件](https://docs.aws.amazon.com/ecr)*。

**Topics**
+ [建立自訂容器](working-with_custom-containers_create.md)
+ [修改專案以使用自訂容器](working-with_custom-containers_modify-project.md)
+ [關於自訂容器的常見問答集](working-with_custom-containers_faq.md)
+ [對自訂容器進行故障診斷](working-with_custom-containers_troubleshooting.md)

# 建立自訂容器
<a name="working-with_custom-containers_create"></a>

這些指示假設您知道如何使用 Docker 和 Amazon Elastic Container Registry (Amazon ECR)。如需 Amazon ECR 的詳細資訊，請參閱《*[Amazon ECR 使用者指南](https://docs.aws.amazon.com/AmazonECR/latest/userguide)*》。

**先決條件**
+ 您用來執行這些動作的 IAM 身分 （使用或角色） 具有使用 Amazon ECR 的正確許可
+ Docker 安裝在您的本機系統上

**建立自訂容器**

1. 建立 `Dockerfile`。

   `Dockerfile` 執行 AWS SimSpace Weaver 應用程式的 會從 Amazon ECR 中的Amazon Linux 2映像開始。

   ```
   # parent image required to run AWS SimSpace Weaver apps
   FROM public.ecr.aws/amazonlinux/amazonlinux:2
   ```

1. 建置您的 `Dockerfile`。

1. 將容器映像上傳至 Amazon ECR。
   + [使用 AWS 管理主控台。](https://docs.aws.amazon.com/AmazonECR/latest/userguide/getting-started-console.html)
   + [使用 AWS Command Line Interface。](https://docs.aws.amazon.com/AmazonECR/latest/userguide/getting-started-cli.html)
**注意**  
如果您在嘗試將容器映像上傳至 Amazon ECR `AccessDeniedException`時發生錯誤，您的 IAM 身分 （使用者或角色） 可能沒有使用 Amazon ECR 的必要許可。您可以將 `AmazonEC2ContainerRegistryPowerUser` AWS 受管政策連接至 IAM 身分，然後再試一次。如需如何連接政策的詳細資訊，請參閱*AWS Identity and Access Management 《 使用者指南*》中的[新增和移除 IAM 身分許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)。

# 修改專案以使用自訂容器
<a name="working-with_custom-containers_modify-project"></a>

這些指示假設您已經知道如何使用 ， AWS SimSpace Weaver 並希望讓您的應用程式儲存和開發工作流程更有效率 AWS 雲端 。

**先決條件**
+ 您在 Amazon Elastic Container Registry (Amazon ECR) 中有自訂容器。如需建立自訂容器的詳細資訊，請參閱 [建立自訂容器](working-with_custom-containers_create.md)。

**若要修改專案以使用自訂容器**

1. 將許可新增至專案的模擬應用程式角色，以使用 Amazon ECR。

   1. 如果您還沒有具有下列許可的 IAM 政策，請建立政策。我們建議使用政策名稱 `simspaceweaver-ecr`。如需如何建立 IAM 政策的詳細資訊，請參閱*AWS Identity and Access Management 《 使用者指南*》中的[建立 IAM 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_create.html)。

      ```
      {
          "Version": "2012-10-17",		 	 	 
          "Statement": [
              {
                  "Sid": "Statement",
                  "Effect": "Allow",
                  "Action": [
                      "ecr:BatchGetImage",
                      "ecr:GetDownloadUrlForLayer",
                      "ecr:GetAuthorizationToken"
                  ],
                  "Resource": "*"
              }
          ]
      }
      ```

   1. 尋找專案模擬應用程式角色的名稱：

      1. 在文字編輯器中，開啟 CloudFormation 範本：

         ```
         sdk-folder\PackagingTools\sample-stack-template.yaml
         ```

      1. 在 下尋找 `RoleName` 屬性`WeaverAppRole`。值是專案模擬應用程式角色的名稱。  
**Example**  

         ```
         AWSTemplateFormatVersion: "2010-09-09"
         Resources:
           WeaverAppRole:
             Type: 'AWS::IAM::Role'
             Properties:
               RoleName: 'weaver-MySimulation-app-role'
               AssumeRolePolicyDocument:
                 Version: "2012-10-17"		 	 	 
                 Statement:
                 - Effect: Allow
                   Principal:
                     Service:
                       - 'simspaceweaver.amazonaws.com'
         ```

   1. 將`simspaceweaver-ecr`政策連接至專案的模擬應用程式角色。如需如何連接政策的詳細資訊，請參閱*AWS Identity and Access Management 《 使用者指南*》中的[新增和移除 IAM 身分許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)。

   1. 導覽至 `sdk-folder`並執行下列命令來更新範例 SimSpace Weaver 堆疊：

      ```
      python setup.py --cloudformation
      ```

1. 在專案的模擬結構描述中指定您的容器映像。
   + 您可以在 下新增選用`default_image`屬性`simulation_properties`，以指定所有網域的預設自訂容器映像。
   + 針對您要使用自訂容器映像`app_config`的網域，在 中新增 `image` 屬性。指定 Amazon ECR 儲存庫 URI 做為值。您可以為每個網域指定不同的映像。
     + 如果`image`未針對網域指定 `default_image` 且已指定 ，則該網域中的應用程式會使用預設映像。
     + 如果 `image` 未指定網域，`default_image`且未指定，則該網域中的應用程式會在標準 SimSpace Weaver 容器中執行。  
**Example 包含自訂容器設定的結構描述程式碼片段**  

   ```
   sdk_version: "1.17.0"
   simulation_properties:
     log_destination_service: "logs"
     log_destination_resource_name: "MySimulationLogs"
     default_entity_index_key_type: "Vector3<f32>"
     default_image: "111122223333.dkr.ecr.us-west-2.amazonaws.com/my-ecr-repository:latest" # image to use if no image specified for a domain
   domains:
     MyCustomDomain:
       launch_apps_via_start_app_call: {}
       app_config:
         package: "s3://weaver-myproject-111122223333-us-west-2/MyViewApp.zip" 
         launch_command: ["MyViewApp"]  
         required_resource_units:
           compute: 1
         endpoint_config:
           ingress_ports:
             - 7000
         image: "111122223333.dkr.ecr.us-west-2.amazonaws.com/my-ecr-repository:latest" # custom container image to use for this domain 
     MySpatialDomain:
       launch_apps_by_partitioning_strategy:
         partitioning_strategy: "MyGridPartitioning"
         grid_partition:
           x: 2
           y: 2
       app_config:
         package: "s3://weaver-myproject-111122223333-us-west-2/MySpatialApp.zip" 
         launch_command: ["MySpatialApp"] 
         required_resource_units:
           compute: 1
         image: "111122223333.dkr.ecr.us-west-2.amazonaws.com/my-ecr-repository:latest" # custom container image to use for this domain
   ```

1. 照常建置和上傳您的專案。

# 關於自訂容器的常見問答集
<a name="working-with_custom-containers_faq"></a>

## Q1. (問題 1)：如果我想要變更容器的內容該怎麼辦？
<a name="working-with_custom-containers_faq_q1"></a>
+ **針對執行中的模擬** – 您無法變更執行中模擬的容器。您必須建立新的容器，並啟動使用該容器的新模擬。
+ **對於新的模擬** – 建立新的容器，將其上傳至 Amazon Elastic Container Registry (Amazon ECR)，然後啟動使用該容器的新模擬。

## Q2. (問題 2): 如何變更模擬的容器映像？
<a name="working-with_custom-containers_faq_q2"></a>
+ **針對執行中的模擬** – 您無法變更執行中模擬的容器。您必須啟動使用新容器的新模擬。
+ **對於新的模擬** – 在專案的模擬結構描述中指定新的容器映像。如需詳細資訊，請參閱[修改專案以使用自訂容器](working-with_custom-containers_modify-project.md)。

# 對自訂容器進行故障診斷
<a name="working-with_custom-containers_troubleshooting"></a>

**Topics**
+ [將映像上傳至 Amazon Elastic Container Registry (Amazon ECR) 時的 AccessDeniedException](working-with_custom-containers_troubleshooting_access-denied.md)
+ [使用自訂容器的模擬無法啟動](working-with_custom-containers_troubleshooting_no-start.md)

# 將映像上傳至 Amazon Elastic Container Registry (Amazon ECR) 時的 AccessDeniedException
<a name="working-with_custom-containers_troubleshooting_access-denied"></a>

如果您在嘗試將容器映像上傳至 Amazon ECR `AccessDeniedException`時發生錯誤，您的 IAM 身分 （使用者或角色） 可能沒有使用 Amazon ECR 的必要許可。您可以將 `AmazonEC2ContainerRegistryPowerUser` AWS 受管政策連接至 IAM 身分，然後再試一次。如需如何連接政策的詳細資訊，請參閱*AWS Identity and Access Management 《 使用者指南*》中的[新增和移除 IAM 身分許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)。

# 使用自訂容器的模擬無法啟動
<a name="working-with_custom-containers_troubleshooting_no-start"></a>

**對秘訣進行故障診斷**
+ 如果您的模擬已啟用記錄，請檢查您的錯誤日誌。
+ 在沒有自訂容器的情況下測試模擬。
+ 在本機測試模擬。如需詳細資訊，請參閱[中的本機開發 SimSpace Weaver](working-with_local-development.md)。