对 Amazon ECR 的拉取访问被拒绝,存储库不存在或可能需要“docker 登录”

问题描述 投票:0回答:2
  1. 我在名为 workshop 的 Amazon ECR 存储库中有一张图片
  2. 我有一个 Dockerfile 来拉那个镜像
  3. CodeBuild 应该从 Dockerfile 构建新镜像

问题:

对 xxxxxxxxxxx.dkr.ecr.eu-central-1.amazonaws.com/workshop 的拉取访问被拒绝,存储库不存在或可能需要“docker 登录”

在我的 buildspec 文件中,我尝试使用 docker 登录,但没有任何变化。

 phases:
  pre_build:
  commands:
   - echo Logging in to Amazon ECR...
   - $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
   - aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 
     xxxxxxxxx.dkr.ecr.eu-central-1.amazonaws.com
   - CODEBUILD_RESOLVED_SOURCE_VERSION="${CODEBUILD_RESOLVED_SOURCE_VERSION:-$IMAGE_TAG}"
   - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)

Dockerfile 看起来像这样:

FROM xxxxxxxxxxx.dkr.ecr.eu-central-1.amazonaws.com/workshop:latest

CMD ["echo", "Hallo!"]

RUN code-server

什么可能导致问题?

docker dockerfile aws-cloudformation aws-codebuild amazon-ecr
2个回答
3
投票

尝试更新您的 aws-cli 并使用最新版本,因为

get-login
已被弃用。

新命令是这样的:

aws ecr get-login-password \
    --region <region> \
| docker login \
    --username AWS \
    --password-stdin <aws_account_id>.dkr.ecr.<region>.amazonaws.com

参考资料:


0
投票

@vasil001

喜欢这里描述:https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-policies.html

如果设置 IAM 策略,您必须指定 ECR 存储库或存储库的完整 arn(带有区域代码和帐户 ID)。

© www.soinside.com 2019 - 2024. All rights reserved.