我正在使用 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/