使用AWS re:Post即您表示您同意 AWS re:Post 使用条款

在AWS CodePipeline的构建阶段中,尽管Docker登录成功,但Docker Push无法正常工作

0

【以下的问题经过翻译处理】 我正在使用AWS CodePipeline准备CI/CD流程。不幸的是,在构建阶段中出现了错误。以下是我的buildspec.yml文件的内容,其中:

AWS_DEFAULT_REGION = eu-central-1

CONTAINER_NAME=cicd-1-app

REPOSITORY_URI = <ACCOUNT_ID>.dkr.ecr.eu-central-1.amazonaws.com/cicd-1-app

version: 0.2
phases:
  install:
    runtime-versions:
      java: corretto11
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws --version
      - TAG="$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)"
      - IMAGE_URI=${REPOSITORY_URI}:${TAG}
  build:
    commands:
      - echo Build started on `date`
      - echo $IMAGE_URI
      - mvn clean package -Ddockerfile.skip
      - docker build --tag $IMAGE_URI .
  post_build:
    commands:
      - printenv
      - echo Build completed on `date`
      - echo $(docker images)
      - echo Pushing docker image
      - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin <ACCOUNT_ID>.dkr.ecr.eu-central-1.amazonaws.com
      - docker push $IMAGE_URI
      - echo push completed
      - printf '[{"name":"%s","imageUri":"%s"}]' $CONTAINER_NAME $IMAGE_URI > imagedefinitions.json
artifacts:
  files:
    - imagedefinitions.json

我收到错误:

[Container] 2022/01/06 19:57:36 Running command aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin <ACCOUNT_ID>.dkr.ecr.eu-central-1.amazonaws.com
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
[Container] 2022/01/06 19:57:37 Running command docker push $IMAGE_URI
The push refers to repository [<ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/cicd-1-app]
37256fb2fd27: Preparing
fe6c1ddaab26: Preparing
d4dfab969171: Preparing
no basic auth credentials

[Container] 2022/01/06 19:57:37 Command did not exit successfully docker push $IMAGE_URI exit status 1
[Container] 2022/01/06 19:57:37 Phase complete: POST_BUILD State: FAILED
[Container] 2022/01/06 19:57:37 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker push $IMAGE_URI. Reason: exit status 1

即使Docker成功登录,仍然出现“no basic auth credentials”错误。你知道可能出了什么问题吗?

此致。

1 回答
0

【以下的回答经过翻译处理】 你是否可能已经在eu-central-1进行了认证,然后尝试推送到us-east-1?

身份验证请求与特定区域相关联,不能跨区域使用。例如,如果你从eu-central-1获取了授权令牌,你不能将其用于对us-east-1中的仓库进行认证。

profile picture
专家
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则