amazon-web-services - 不能拉容器错误 : context canceled error when starting ECS task

标签 amazon-web-services aws-ecr

我正在使用 Fargate 启动 ECS 任务,并且容器在 PENDING 几分钟后最终处于 STOPPED 状态。状态给出以下错误消息:

CannotPullContainerError: context canceled

我正在使用 PrivateLink 允许 ECS 主机与 ECR 注册表对话,而无需通过公共(public) Internet,这就是它的配置方式(无服务器语法增强 CloudFormation):
      Properties:
        PrivateDnsEnabled: true
        ServiceName: com.amazonaws.ap-southeast-2.ecr.dkr
        SubnetIds:
          - { Ref: frontendSubnet1 }
          - { Ref: frontendSubnet2 }
        VpcEndpointType: Interface
        VpcId: { Ref: frontendVpc }

关于导致错误的任何想法?

最佳答案

您是否还添加了 S3 端点?
这是我的模板的一个工作片段,我能够通过 aws 支持解决问题:

  EcrDkrEndpoint:
Type: 'AWS::EC2::VPCEndpoint'
Properties:
  PrivateDnsEnabled: true
  SecurityGroupIds: [!Ref 'FargateContainerSecurityGroup']
  ServiceName: !Sub 'com.amazonaws.${AWS::Region}.ecr.dkr'
  SubnetIds: [!Ref 'PrivateSubnetOne', !Ref 'PrivateSubnetTwo']
  VpcEndpointType: Interface
  VpcId: !Ref 'VPC'

对于 S3,您需要知道路由表是必要的 - 通常您希望使用与 Internet 网关相同的路由表,其中包含路由 0.0.0.0/0
  S3Endpoint:
Type: 'AWS::EC2::VPCEndpoint'
Properties:
  ServiceName: !Sub 'com.amazonaws.${AWS::Region}.s3'
  VpcEndpointType: Gateway
  VpcId: !Ref 'VPC'
  RouteTableIds: [!Ref 'PrivateRouteTable'] 

如果没有 cloudwatch 的端点,您将再次失败,这也是必要的:
  CloudWatchEndpoint:
Type: 'AWS::EC2::VPCEndpoint'
Properties:
  PrivateDnsEnabled: true
  SecurityGroupIds: [!Ref 'FargateContainerSecurityGroup']
  ServiceName: !Sub 'com.amazonaws.${AWS::Region}.logs'
  SubnetIds: [!Ref 'PrivateSubnetOne', !Ref 'PrivateSubnetTwo']
  VpcEndpointType: Interface
  VpcId: !Ref 'VPC'

编辑:私有(private)路由表:
  PrivateRoute:
Type: AWS::EC2::Route
DependsOn: InternetGatewayAttachement
Properties:
  RouteTableId: !Ref 'PublicRouteTable'
  DestinationCidrBlock: '0.0.0.0/0'
  GatewayId: !Ref 'InternetGateway'

关于amazon-web-services - 不能拉容器错误 : context canceled error when starting ECS task,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58688475/

相关文章:

amazon-web-services - AWS ECS 跨多个实例处理 DNS 子域

ruby-on-rails - 使用 ACM 的证书在 elasticbeanstalk 中强制使用 https

macos - Docker推送到Amazon ECR会减慢或卡住

amazon-web-services - 在 Jenkinsfile 中对 ECR 进行身份验证,以便我可以提取图像来运行构建?

kubernetes - 需要建议如何使Spinnaker与AWS ECR配合使用?

amazon-web-services - TOKEN 端点返回没有客户端密码的 invalid_client

python - 如何在 Amazon Elastic Beanstalk 上安装 opencv-python

php - AWS bean 茎 : Exponential backoff for SQS?

docker - 如何在我的 PATH 中设置 docker-credential-ecr-login 在 GitLab CI 中的任何其他内容之前

aws-ecr - 从图像中删除标签