将图像推送到 ECR,得到 "Retrying in ... seconds"
Pushing an image to ECR, getting "Retrying in ... seconds"
我最近在 AWS ECR 中创建了一个新的存储库,我正在尝试推送一个图像。我是 copy/pasting 通过存储库页面上的“查看推送命令”按钮提供的说明。我将复制到这里以供参考:
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 123456789.dkr.ecr.us-west-2.amazonaws.com
("登录成功")
docker build -t myorg/myapp .
docker tag myorg/myapp:latest 123456789.dkr.ecr.us-west-2.amazonaws.com/myorg/myapp:latest
docker push 123456789.dkr.ecr.us-west-2.amazonaws.com/myorg/myapp:latest
但是,当我到达 docker push
步骤时,我看到:
> docker push 123456789.dkr.ecr.us-west-2.amazonaws.com/myorg/myapp:latest
The push refers to repository [123456789.dkr.ecr.us-west-2.amazonaws.com/myorg/myapp]
a53c8ed5f326: Retrying in 1 second
78e16537476e: Retrying in 1 second
b7e38d172e62: Retrying in 1 second
f1ff72b2b1ca: Retrying in 1 second
33b67aceeff0: Retrying in 1 second
c3a550784113: Waiting
83fc4b4db427: Waiting
e8ade0d39f19: Waiting
487d5f9ec63f: Waiting
b24e42eb9639: Waiting
9262398ff7bf: Waiting
804aae047b71: Waiting
5d33f5d87bf5: Waiting
4e38024e7e09: Waiting
EOF
我想知道这是否与与此存储库关联的 permissions/policies 有关。现在没有附加到此存储库的语句。那是缺少的部分吗?如果是这样,该声明会是什么样子?我已经试过了,但没有效果:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPutImage",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789:root"
},
"Action": "ecr:PutImage"
}
]
}
奖励积分:
我最终想在 CDK CodeBuildAction 中使用它。我遇到了与上面相同的错误,所以我检查我是否在我的本地终端中得到了相同的结果,我就是这样。因此,如果在 CDK CodeBuildAction 中使用的政策声明需要不同,那么这些细节也将不胜感激。
提前感谢您的建议。
原来是 missing/misconfigured 政策。通过使用 AmazonEC2ContainerRegistryPowerUser
托管策略添加一个角色,我能够让它在 CodeBuild 中工作:
new CodeBuildAction({
actionName: "ApplicationBuildAction",
input: this.applicationSourceOutput,
outputs: [this.applicationBuildOutput],
project: new PipelineProject(this, "ApplicationBuildProject", {
vpc: this.codeBuildVpc,
securityGroups: [this.codeBuildSecurityGroup],
environment: {
buildImage: LinuxBuildImage.STANDARD_5_0,
privileged: true,
},
environmentVariables: {
ECR_REPO_URI: {
value: ECR_REPO_URI,
},
ECR_REPO_NAME: {
value: ECR_REPO_NAME,
},
AWS_REGION: {
value: this.region,
}
},
buildSpec: BuildSpec.fromObject({
version: "0.2",
phases: {
pre_build: {
commands: [
"echo 'Logging into Amazon ECR...'",
"aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REPO_URI",
"COMMIT_HASH=$(echo \"$CODEBUILD_RESOLVED_SOURCE_VERSION\" | head -c 8)"
]
},
build: {
commands: [
"docker build -t $ECR_REPO_NAME:latest ."
]
},
post_build: {
commands: [
"docker tag $ECR_REPO_NAME:latest $ECR_REPO_URI/$ECR_REPO_NAME:latest",
"docker tag $ECR_REPO_NAME:latest $ECR_REPO_URI/$ECR_REPO_NAME:$COMMIT_HASH",
"docker push $ECR_REPO_URI/$ECR_REPO_NAME:latest",
"docker push $ECR_REPO_URI/$ECR_REPO_NAME:$COMMIT_HASH",
]
}
}
}),
// * * ADDED THIS ROLE HERE * *
role: new Role(this, "application-build-project-role", {
assumedBy: new ServicePrincipal("codebuild.amazonaws.com"),
managedPolicies: [ManagedPolicy.fromAwsManagedPolicyName("AmazonEC2ContainerRegistryPowerUser")]
})
}),
});
我在尝试使用 AWS 和 Docker CLI 手动上传图像时遇到了同样的问题。我能够通过进入 ECR -> Repositories -> Permissions 然后添加一个带有 principal:*
的新策略声明和以下操作来修复它:
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:CompleteLayerUpload",
"ecr:GetDownloadUrlForLayer",
"ecr:InitiateLayerUpload",
"ecr:PutImage",
"ecr:UploadLayerPart"
请务必添加更多限制性主体。我只是想看看在这种情况下权限是否是问题所在,果然是。
问题是您的 iam-user 没有完全访问 ecr 的权限,因此请将以下政策附加到您的 iam-user。
follow photo for policy attachment
当 ECR 中不存在存储库时,我遇到了这个问题 - 我认为推送会创建它,但事实并非如此。
在推送之前创建它解决了问题。
我最近在 AWS ECR 中创建了一个新的存储库,我正在尝试推送一个图像。我是 copy/pasting 通过存储库页面上的“查看推送命令”按钮提供的说明。我将复制到这里以供参考:
aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 123456789.dkr.ecr.us-west-2.amazonaws.com
("登录成功")
docker build -t myorg/myapp .
docker tag myorg/myapp:latest 123456789.dkr.ecr.us-west-2.amazonaws.com/myorg/myapp:latest
docker push 123456789.dkr.ecr.us-west-2.amazonaws.com/myorg/myapp:latest
但是,当我到达 docker push
步骤时,我看到:
> docker push 123456789.dkr.ecr.us-west-2.amazonaws.com/myorg/myapp:latest
The push refers to repository [123456789.dkr.ecr.us-west-2.amazonaws.com/myorg/myapp]
a53c8ed5f326: Retrying in 1 second
78e16537476e: Retrying in 1 second
b7e38d172e62: Retrying in 1 second
f1ff72b2b1ca: Retrying in 1 second
33b67aceeff0: Retrying in 1 second
c3a550784113: Waiting
83fc4b4db427: Waiting
e8ade0d39f19: Waiting
487d5f9ec63f: Waiting
b24e42eb9639: Waiting
9262398ff7bf: Waiting
804aae047b71: Waiting
5d33f5d87bf5: Waiting
4e38024e7e09: Waiting
EOF
我想知道这是否与与此存储库关联的 permissions/policies 有关。现在没有附加到此存储库的语句。那是缺少的部分吗?如果是这样,该声明会是什么样子?我已经试过了,但没有效果:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPutImage",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789:root"
},
"Action": "ecr:PutImage"
}
]
}
奖励积分: 我最终想在 CDK CodeBuildAction 中使用它。我遇到了与上面相同的错误,所以我检查我是否在我的本地终端中得到了相同的结果,我就是这样。因此,如果在 CDK CodeBuildAction 中使用的政策声明需要不同,那么这些细节也将不胜感激。
提前感谢您的建议。
原来是 missing/misconfigured 政策。通过使用 AmazonEC2ContainerRegistryPowerUser
托管策略添加一个角色,我能够让它在 CodeBuild 中工作:
new CodeBuildAction({
actionName: "ApplicationBuildAction",
input: this.applicationSourceOutput,
outputs: [this.applicationBuildOutput],
project: new PipelineProject(this, "ApplicationBuildProject", {
vpc: this.codeBuildVpc,
securityGroups: [this.codeBuildSecurityGroup],
environment: {
buildImage: LinuxBuildImage.STANDARD_5_0,
privileged: true,
},
environmentVariables: {
ECR_REPO_URI: {
value: ECR_REPO_URI,
},
ECR_REPO_NAME: {
value: ECR_REPO_NAME,
},
AWS_REGION: {
value: this.region,
}
},
buildSpec: BuildSpec.fromObject({
version: "0.2",
phases: {
pre_build: {
commands: [
"echo 'Logging into Amazon ECR...'",
"aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REPO_URI",
"COMMIT_HASH=$(echo \"$CODEBUILD_RESOLVED_SOURCE_VERSION\" | head -c 8)"
]
},
build: {
commands: [
"docker build -t $ECR_REPO_NAME:latest ."
]
},
post_build: {
commands: [
"docker tag $ECR_REPO_NAME:latest $ECR_REPO_URI/$ECR_REPO_NAME:latest",
"docker tag $ECR_REPO_NAME:latest $ECR_REPO_URI/$ECR_REPO_NAME:$COMMIT_HASH",
"docker push $ECR_REPO_URI/$ECR_REPO_NAME:latest",
"docker push $ECR_REPO_URI/$ECR_REPO_NAME:$COMMIT_HASH",
]
}
}
}),
// * * ADDED THIS ROLE HERE * *
role: new Role(this, "application-build-project-role", {
assumedBy: new ServicePrincipal("codebuild.amazonaws.com"),
managedPolicies: [ManagedPolicy.fromAwsManagedPolicyName("AmazonEC2ContainerRegistryPowerUser")]
})
}),
});
我在尝试使用 AWS 和 Docker CLI 手动上传图像时遇到了同样的问题。我能够通过进入 ECR -> Repositories -> Permissions 然后添加一个带有 principal:*
的新策略声明和以下操作来修复它:
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:CompleteLayerUpload",
"ecr:GetDownloadUrlForLayer",
"ecr:InitiateLayerUpload",
"ecr:PutImage",
"ecr:UploadLayerPart"
请务必添加更多限制性主体。我只是想看看在这种情况下权限是否是问题所在,果然是。
问题是您的 iam-user 没有完全访问 ecr 的权限,因此请将以下政策附加到您的 iam-user。
follow photo for policy attachment
当 ECR 中不存在存储库时,我遇到了这个问题 - 我认为推送会创建它,但事实并非如此。
在推送之前创建它解决了问题。