プライベートサブネットの ECS で CannotPullContainerError The task cannot pull i/o timeout を回避するには
困っていた内容
プライベートサブネットで ECS タスクを実行したところi/o timeout
でタスクの起動に失敗しました。
CannotPullContainerError:
The task cannot pull 【イメージ URI】 from the registry 【イメージ URI】. There is a connection issue between the task and the registry. Check your task network configuration. : failed to copy: httpReadSeeker: failed open: failed to do request: Get 【イメージ URI】: dial tcp ...:
i/o timeout
プライベートサブネットで ECR のイメージを使用しているので、ecr.dkr
とecr.api
の VPC エンドポイントは作成済みで、セキュリティグループなども問題ありませんでした。
ECS タスクが正常に起動する方法を教えてください。
どう対応すればいいの?
S3 の VPC エンドポイントも作成してください。
Amazon ECR インターフェイス VPC エンドポイント (AWS PrivateLink) - Amazon ECR
Amazon ECS タスクで Amazon ECR からプライベートイメージをプルするには、Amazon S3 のゲートウェイエンドポイントを作成する必要があります。Amazon ECR は Amazon S3 を使用してイメージレイヤーを保存するため、ゲートウェイエンドポイントが必要です。
ECR からイメージをプルする際、ECR に加えて S3 へのアクセス経路も必要です。
プライベートサブネットなど S3 へのアクセス経路がないネットワーク環境では、CannotPullContainerError The task cannot pull ... i/o timeout
でタスクの起動が失敗することが想定されます。
そのため、S3 へのアクセス経路があるか確認し、状況に応じて S3 の VPC エンドポイントを作成してください。
S3 の VPC エンドポイントが既にある場合、セキュリティグループ等でアクセスを遮断していないか確認してください。
参考資料
- Amazon ECR インターフェイス VPC エンドポイント (AWS PrivateLink) - Amazon ECR
- Amazon ECS での CannotPullContainer タスクエラー - Amazon Elastic Container Service
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.
このエラーは、タスクが Amazon ECR に接続できないことを示します。リポジトリ URI リポジトリへの接続を確認してください。
Amazon ECR 仮想プライベートクラウド (VPC) のエンドポイントと Amazon Simple Storage Service (Amazon S3) ゲートウェイのエンドポイントで AWS PrivateLink を使用します。