CannotPullContainerError:启动ECS任务时上下文取消错误

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

CannotPullContainerError: context canceled

我正在使用PrivateLink允许ECS主机与ECR注册表进行对话,而不必通过公共Internet,这就是它的配置方式(无服务器语法增强CloudFormation):

      Properties:
        PrivateDnsEnabled: true
        ServiceName: com.amazonaws.ap-southeast-2.ecr.dkr
        SubnetIds:
          - { Ref: frontendSubnet1 }
          - { Ref: frontendSubnet2 }
        VpcEndpointType: Interface
        VpcId: { Ref: frontendVpc }

关于导致错误的原因有什么想法?

amzonpb365 回答:CannotPullContainerError:启动ECS任务时上下文取消错误

您还添加了一个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'

编辑:专用路由表:

  PrivateRoute:
Type: AWS::EC2::Route
DependsOn: InternetGatewayAttachement
Properties:
  RouteTableId: !Ref 'PublicRouteTable'
  DestinationCidrBlock: '0.0.0.0/0'
  GatewayId: !Ref 'InternetGateway'
,

我发现我不仅需要s3的vpc终结点,aws日志和@graphik_的答案中详细说明的两个ecr终结点,而且我还需要确保终结点上的安全组允许从安全性入口访问HTTPS组在Farscape容器上。

Farscape容器上的安全组需要通过HTTPS到vpce端点安全组以及s3的pl-7ba54012 IP组进行出口访问。

这和到路由表中的pl-7ba54012的路由似乎是整体图。

vpce上也有策略,我将其保留为默认的“所有访问”,但您可以对其进行强化,以仅允许运行Fargate容器的角色进行访问。

本文链接:https://www.f2er.com/3168631.html

大家都在问