

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

# Amazon ECS 中的 CannotPullContainer 任務錯誤
<a name="task_cannot_pull_image"></a>

下列錯誤表示任務無法啟動，因為 Amazon ECS 無法擷取指定的容器映像。

**注意**  
1.4 Fargate 平台版本會截斷長的錯誤訊息。

若要使用 檢查已停止的任務是否有錯誤訊息 AWS 管理主控台，請參閱 [檢視 Amazon ECS 已停止任務錯誤](stopped-task-errors.md)。

**提示**  
您可以[Amazon ECS MCP 伺服器](ecs-mcp-introduction.md)搭配 AI 助理使用 ，使用自然語言調查影像提取錯誤。

**Topics**
+ [The task can’t pull the image. Check that the role has the permissions to pull images from the registry.](#pull-request-image-not-found)
+ [The task cannot pull ‘*image-name*’ from the Amazon ECR repository ‘*repository URI*’. There is a connection issue between the task and Amazon ECR. Check your task network configuration.](#pull-image-io-timeout)
+ [The task can’t pull the image. Check your network configuration](#pull-request-image-not-found-network)
+ [CannotPullContainerError: pull image manifest has been retried 5 time(s): failed to resolve ref](#pull-request-image-tag)
+ [API error (500): Get https://111122223333.dkr.ecr.us-east-1.amazonaws.com/v2/: net/http: request canceled while waiting for connection](#request-canceled)
+ [API 錯誤](#pull-request-api-error)
+ [write /var/lib/docker/tmp/*GetImageBlob111111111*: no space left on device](#pull-request-write-error)
+ [ERROR: toomanyrequests: Too Many Requests or You have reached your pull rate limit.](#container-pull-too-many-requests)
+ [Error response from daemon: Get *url*: net/http: request canceled while waiting for connection](#container-pull-request-canceled-connection)
+ [ref pull has been retried 1 time(s): failed to copy: httpReaderSeeker: failed open: unexpected status code](#container-pull-failed-open)
+ [pull access denied](#container-pull-access-denied.title)
+ [pull command failed: panic: runtime error: invalid memory address or nil pointer dereference](#container-pull-runtime-error.title)
+ [error pulling image conf/error pulling image configuration](#container-pull-pulling-image.title)
+ [內容已取消](#container-pull-context-canceled)

## The task can’t pull the image. Check that the role has the permissions to pull images from the registry.
<a name="pull-request-image-not-found"></a>

此錯誤表示由於許可問題，任務無法提取任務定義中指定的映像。

若要解決此問題：

1. 檢查映像是否存在於*儲存庫*中。如需有關檢視映像的資訊，請參閱 *Amazon Elastic Container Registry User Guide* 中的 [Viewing image details in Amazon ECR](https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-info.html)。

1. 確認 *role-arn* 具有提取映像的正確許可。

   如需有關如何更新角色的資訊，請參閱 *AWS Identity and Access Management Use Guide* 中的 [Update permissions for a role](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_update-role-permissions.html)。

   任務使用以下任一角色：
   + 對於使用 Fargate 的任務，此為任務執行角色。如需有關 Amazon ECR 額外許可的資訊，請參閱 [Fargate 任務透過介面端點提取 Amazon ECR 映像的許可](task_execution_IAM_role.md#task-execution-ecr-conditionkeys)。
   + 對於使用 EC2 的任務，此為容器執行個體角色。如需有關 Amazon ECR 額外許可的資訊，請參閱 [Amazon ECR 許可](instance_IAM_role.md#container-instance-role-ecr)。

## The task cannot pull ‘*image-name*’ from the Amazon ECR repository ‘*repository URI*’. There is a connection issue between the task and Amazon ECR. Check your task network configuration.
<a name="pull-image-io-timeout"></a>

此錯誤表示任務無法連線至 Amazon ECR。檢查*儲存庫 URI* 儲存庫的連線。

如需有關如何確認與解決此問題的資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。

## The task can’t pull the image. Check your network configuration
<a name="pull-request-image-not-found-network"></a>

此錯誤表示任務無法連線至 Amazon ECR。

如需有關如何確認與解決此問題的資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。

## CannotPullContainerError: pull image manifest has been retried 5 time(s): failed to resolve ref
<a name="pull-request-image-tag"></a>

此錯誤表示任務無法提取映像。

若要解決此問題，您可以：
+ 確認任務定義中指定的映像符合儲存庫中的映像。
+ Amazon ECS 會強制保障映像版本穩定性。若原始映像不再可用，您就會遇到此錯誤。映像標籤是強制實施此項機制的關鍵組成。請將任務定義中的映像標籤從 :latest 更改為特定版本。如需詳細資訊，請參閱[容器映像解析](deployment-type-ecs.md#deployment-container-image-stability)。

如需有關如何確認與解決此問題的資訊，請參閱[驗證 Amazon ECS 已停止任務的連線狀態](verify-connectivity.md)。

## API error (500): Get https://111122223333.dkr.ecr.us-east-1.amazonaws.com/v2/: net/http: request canceled while waiting for connection
<a name="request-canceled"></a>

此錯誤表示連線已逾時，原因是不存在通往網際網路的路由。

要解決此問題，則可以採取下列方式：
+ 針對公有子網路中的任務，您必須在啟動任務時，將 **Auto-assign public IP** (自動指派公有 IP) 指定為 **ENABLED** (啟用)。如需詳細資訊，請參閱[將應用程式作為 Amazon ECS 任務執行](standalone-task-create.md)。
+ 針對在私有子網路中的任務，則必須在啟動任務時，將 **Auto-assign public IP** (自動指派公有 IP) 指定為 **DISABLED** (停用)，並設定 VPC 中的 NAT 閘道，以便將請求路由至網際網路。如需詳細資訊，請參閱 *Amazon VPC 使用者指南*中的 [NAT 閘道](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html)。

## API 錯誤
<a name="pull-request-api-error"></a>

此錯誤表示 Amazon ECR 端點存在連線問題。

如需如何解決此問題的資訊，請參閱 支援 網站上的[如何解決 Amazon ECS 中的 Amazon ECR 錯誤「CannotPullContainerError： API 錯誤」](https://aws.amazon.com/premiumsupport/knowledge-center/ecs-pull-container-api-error-ecr/)。

## write /var/lib/docker/tmp/*GetImageBlob111111111*: no space left on device
<a name="pull-request-write-error"></a>

此錯誤表示磁碟空間不足。

若要解決這個問題，請釋放磁碟空間。

如果使用 Amazon ECS 最佳化 AMI，您可以透過下列命令來擷取檔案系統上最大的前 20 個檔案：

```
du -Sh / | sort -rh | head -20
```

輸出範例：

```
5.7G    /var/lib/docker/containers/50501b5f4cbf90b406e0ca60bf4e6d4ec8f773a6c1d2b451ed8e0195418ad0d2
1.2G    /var/log/ecs
594M    /var/lib/docker/devicemapper/mnt/c8e3010e36ce4c089bf286a623699f5233097ca126ebd5a700af023a5127633d/rootfs/data/logs
...
```

在某些情況下，執行容器可能會填滿根磁碟區。如果容器使用預設的 `json-file` 日誌驅動程式，而不具有 `max-size` 限制，則該日誌檔案可能佔用大部分空間。您可以使用 `docker ps` 命令，透過將目錄名稱從上面的輸出映射至容器 ID，來驗證哪個容器正在使用該空間。例如：

```
CONTAINER ID   IMAGE                            COMMAND             CREATED             STATUS              PORTS                            NAMES
50501b5f4cbf   amazon/amazon-ecs-agent:latest   "/agent"            4 days ago          Up 4 days                                            ecs-agent
```

在預設情況下，當使用 `json-file` 日誌驅動程式時，Docker 會擷取所有容器的標準輸出 (和標準錯誤)，並使用 JSON 格式將其寫入檔案中。您可以將 `max-size` 設定為日誌驅動程式選項，以防止日誌檔案佔用過多空間。如需詳細資訊，請參閱 Docker 文件中的 [JSON File logging driver](https://docs.docker.com/engine/logging/drivers/json-file/)。

下列是一個容器定義片段，顯示如何使用此選項：

```
{
    "log-driver": "json-file",
    "log-opts": {
        "max-size": "256m"
    }
}
```

如果容器日誌佔用太多磁碟空間，則可使用 `awslogs` 日誌驅動程式。`awslogs` 日誌驅動程式會將日誌傳送至 CloudWatch，以釋放原本要給容器執行個體上的容器日誌使用的磁碟空間。如需詳細資訊，請參閱[將 Amazon ECS 日誌傳送至 CloudWatch](using_awslogs.md)。

您可能需要更新 Docker 可存取的磁碟大小。

如需詳細資訊，請參閱 [CannotPullContainerError: no space left on device](https://repost.aws/questions/QUx6Ix1R1SSNisYSs1Sw8EBA/cannotpullcontainererror-no-space-left-on-device)。

## ERROR: toomanyrequests: Too Many Requests or You have reached your pull rate limit.
<a name="container-pull-too-many-requests"></a>

此錯誤表示存在 Docker Hub 速率限制。

如果收到下列其中一項錯誤訊息，您很可能會達到 Docker Hub 速率限制：

如需 Docker Hub 速率限制的詳細資訊，請參閱[了解 Docker Hub 速率限制](https://www.docker.com/increase-rate-limits)。

如果您已提升 Docker Hub 速率限制，並且需要身分驗證容器執行個體的 Docker 提取，請參閱[容器執行個體的私有登錄檔身分驗證](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/private-auth-container-instances.html)。

## Error response from daemon: Get *url*: net/http: request canceled while waiting for connection
<a name="container-pull-request-canceled-connection"></a>

此錯誤表示連線已逾時，原因是不存在通往網際網路的路由。

要解決此問題，則可以採取下列方式：
+ 針對公有子網路中的任務，您必須在啟動任務時，將 **Auto-assign public IP** (自動指派公有 IP) 指定為 **ENABLED** (啟用)。如需詳細資訊，請參閱[將應用程式作為 Amazon ECS 任務執行](standalone-task-create.md)。
+ 針對在私有子網路中的任務，則必須在啟動任務時，將 **Auto-assign public IP** (自動指派公有 IP) 指定為 **DISABLED** (停用)，並設定 VPC 中的 NAT 閘道，以便將請求路由至網際網路。如需詳細資訊，請參閱 *Amazon VPC 使用者指南*中的 [NAT 閘道](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html)。

## ref pull has been retried 1 time(s): failed to copy: httpReaderSeeker: failed open: unexpected status code
<a name="container-pull-failed-open"></a>

此錯誤表示複製映像時失敗。

若要解決此問題，請檢閱下列文章：
+ 如需 Fargate 任務，請參閱[如何解決 Fargate 上 Amazon ECS 任務的 "cannotpullcontainererror" 錯誤](https://aws.amazon.com/premiumsupport/knowledge-center/ecs-fargate-pull-container-error/)。
+ 如需其他任務，請參閱[如何解決 Fargate 上 Amazon ECS 任務的 "cannotpullcontainererror" 錯誤](https://aws.amazon.com/premiumsupport/knowledge-center/ecs-pull-container-error/)。

## pull access denied
<a name="container-pull-access-denied.title"></a>

此錯誤表示無法存取映像。

若要解決此問題，您可能需要使用 Amazon ECR 驗證 Docker 用戶端。如需詳細資訊，請參閱 *Amazon ECR User Guide* 中的 [Private registry authentication](https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html)。

## pull command failed: panic: runtime error: invalid memory address or nil pointer dereference
<a name="container-pull-runtime-error.title"></a>

此錯誤表示由於記憶體位址無效或空指標解除參照，無法存取映像。

若要解決此問題：
+ 檢查您是否擁有可連接 Amazon S3 的安全群組規則。
+ 使用閘道端點時，必須在路由表中新增路由，才能存取端點。

## error pulling image conf/error pulling image configuration
<a name="container-pull-pulling-image.title"></a>

此錯誤表示已達到速率限制或發生網路錯誤：

若要解決此問題，請參閱[我的 Amazon ECS EC2 啟動類型任務中的如何解決「CannotPullContainerError」錯誤](https://repost.aws/knowledge-center/ecs-pull-container-error)。

## 內容已取消
<a name="container-pull-context-canceled"></a>

此錯誤表示內容已取消。

此錯誤的原因通常是因為您的任務所使用的 VPC 沒有路由，而無法從 Amazon ECR 提取容器映像。