我正在尝试将docker映像推送到Amazon ECR注册表。我使用docker客户端docker版本1.9.1,构建a34a1d5。我使用aws ecr get-login -region us-east-1来获得docker登录信用。然后我成功登录这些学分如下:

docker login -u AWS -p XXXX -e none https://####.dkr.ecr.us-east-1.amazonaws.com
WARNING: login credentials saved in /Users/ar/.docker/config.json
Login Succeeded

但当我试图推动我的图像,我得到以下错误:

$ docker push ####.dkr.ecr.us-east-1.amazonaws.com/image:latest
The push refers to a repository [####.dkr.ecr.us-east-1.amazonaws.com/image] (len: 1)
bcff5e7e3c7c: Preparing 
Post https://####.dkr.ecr.us-east-1.amazonaws.com/v2/image/blobs/uploads/: no basic auth credentials

我确保aws用户具有正确的权限。我还确保存储库允许用户推送到它。为了确保这不是一个问题,我将注册表设置为允许所有用户完全访问。没有什么可以改变“no basic auth credentials”错误。我不知道如何开始调试,因为所有的流量都是加密的。

更新

So I had a bit of Homer Simpson D'Oh moment when I realized the root cause of my problem. I have access to multiple AWS accounts. Even though I was using aws configure to set my credentials for the account where I had setup my repository the aws cli was actually using the environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. So when I did aws ecr get-login it was returning a login for the wrong account. I failed to notice that the account numbers were different until I just went back now to try some of the proposed answers. When I remove the environment variables everything works correctly. I guess the motto of the story is if you hit this error, make sure that the repository you are logging into matches the tag you have applied to the image.


当前回答

在我的情况下(可能在所有情况下),此错误是由于拥有多个AWS帐户造成的。因此,AWS ECR没有使用与AWS帐户关联的正确AWS凭据。

我尝试了这里提到的多种解决方案,但都没有成功。它在使用令牌而不是用户名和密码后工作。我按照这里的说明把它修好了。https://btburnett.com/2017/01/docker-login-for-amazon-aws-ecr-using-windows-powershell.html

其他回答

Mac OSX

确保您的“auths”密钥与您的凭据存储密钥完全匹配

检查docker配置:

猫~ / .docker / json

结果:样本

{
    "auths": {
        "https://55511155511.dkr.ecr.us-east-1.amazonaws.com": {}
    },
    "HttpHeaders": {
        "User-Agent": "Docker-Client/19.03.5 (darwin)"
    },
    "credsStore": "osxkeychain"
}

注意,“auths”值是一个空对象,docker正在使用一个凭据存储“osxkeychain”。

打开Mac的“Keychain Access”应用程序,找到名称“Docker Credentials”

注意Where:字段

确保认证输入~/.docker/config。json匹配Keychain Access中的Where:字段。

如果认证者输入~/.docker/config. conf。在keychain中:字段,你可能会得到Login Succeeded from docker Login…但是仍然得到 错误:服务“web”未能构建:获得https://55511155511.dkr.ecr.us-east-1.amazonaws.com/v2/path/to/image/latest:没有基本的身份验证凭据,当你试图拉。

在我的例子中,我需要添加https://

原始

    "auths": {
        "55511155511.dkr.ecr.us-east-1.amazonaws.com": {}
    },

固定

    "auths": {
        "https://55511155511.dkr.ecr.us-east-1.amazonaws.com": {}
    },

如果你运行$(aws ecr get-login——region us-east-1),一切都会为你完成

2021年7月更新:

在AWS CLI的版本1中,get-login现在已弃用。如果您正在使用AWS CLI的版本2,则必须使用get-login-password。

您可以将get-login-password的输出输出到docker登录命令,以验证docker到您的ECR注册表:

aws ecr get-login-password | docker login --username AWS --password-stdin ####.dkr.ecr.us-east-1.amazonaws.com

现在你应该能够docker推送,并让它直接进入你的ECR注册表。

Docker CLI不支持原生IAM鉴权方法。要验证和授权Docker推拉请求,请遵循此步骤。

步骤- 1

检查aws凭证是否正确配置。要配置AWS凭据,运行以下命令并提供AWS凭据。

aws configure

步骤- 2

你可以使用get-login-password将Docker认证到Amazon ECR私有注册表(推荐)

Linux和MSC

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

对于windows

(Get-ECRLoginCommand).Password | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.<your region>.amazonaws.com

or

您也可以使用——get-login方法(但是暴露凭据)(不推荐)。

Linux和MAC

$(aws ecr get-login --region <your region> --no-include-email)

对于windows

Invoke-Expression -Command (Get-ECRLoginCommand -Region <your region>).Command

如果你的登录成功,那么你就可以开始了。否则,请参考aws文档查看错误

步骤- 3

将您的映像推到回购

标记你的图像 Docker标签<aws_account_id>.dkr.ecr..amazonaws.com/my-web-app 使用以下命令推送图像。 Docker push <aws_account_id>.dkr.ecr..amazonaws.com/my-web-app

注意:这是基于令牌的登录和生成的授权令牌 仅12H有效

如果这对谁有帮助的话……

我的问题是,我必须使用——profile选项,以便使用来自凭证文件的正确配置文件进行身份验证。

接下来,我忽略了——region [region_name]命令,这也给出了“no basic auth credentials”错误。

我的解决方案是改变我的命令:

Aws ecr get-login

:

Aws——profile [profile_name] ecr get-login——region [region_name]

例子:

Aws—配置文件foo ecr get-login—区域us-east-1

希望这能帮助到别人!

我也遇到过同样的问题,用这个命令解决了它。我可以用,请按照你的账号更新 这是为Ubuntu机器,其中AWS-CLI需要安装Docker

algorithm_name='multi-model-xgboost'

account=$(aws sts get-caller-identity --query Account --output text)

# Get the region defined in the current configuration
region=$(aws configure get region)

aws ecr get-login-password --region ${region} | docker login --username AWS --password-stdin ${account}.dkr.ecr.${region}.amazonaws.com/${algorithm_name}