简体   繁体   English

如何使用 hdockerpy 和 aws ecr 存储库修复无基本身份验证凭据错误?

[英]How fix no basic auth credentials error wit hdockerpy and aws ecr repo?

I m trying to execute the folowing python code:我正在尝试执行以下 python 代码:

import logging
import sys
import docker, boto3
from base64 import b64decode

logging.basicConfig(stream=sys.stdout, level=logging.INFO)

LOCAL_REPOSITORY = '111111111111.dkr.ecr.us-east-1.amazonaws.com/my_repo:latest'

image = '111111111111.dkr.ecr.us-east-1.amazonaws.com/my_repo'
ecr_registry, _ = image.split('/', 1)
client = docker.from_env()

# Get login credentials from AWS for the ECR registry.
ecr = boto3.client('ecr')
response = ecr.get_authorization_token()
token = b64decode(response['authorizationData'][0]['authorizationToken'])
username, password = token.decode('utf-8').split(':', 1)

# Log in to the ECR registry with Docker.
client.login(username, password, registry=ecr_registry)
logging.info("loggined")
client.images.pull(image,   auth_config={
  username: username,
  password: password
})

And got exception:并得到了例外:

C:\myPath>python app/pull_example.py
INFO:botocore.credentials:Found credentials in environment variables.
INFO:root:loggined
Traceback (most recent call last):
  File "C:\Python3\lib\site-packages\docker\api\client.py", line 261, in _raise_for_status
    response.raise_for_status()
  File "C:\Python3\lib\site-packages\requests\models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localnpipe/v1.35/images/create?fromImage=111111111111.dkr.ecr.us-east-1.amazonaws.com%2Fmy_repo

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "app/pull_example.py", line 41, in <module>
    password: password
  File "C:\Python3\lib\site-packages\docker\models\images.py", line 445, in pull
    repository, tag=tag, stream=True, **kwargs
  File "C:\Python3\lib\site-packages\docker\api\image.py", line 415, in pull
    self._raise_for_status(response)
  File "C:\Python3\lib\site-packages\docker\api\client.py", line 263, in _raise_for_status
    raise create_api_error_from_http_exception(e)
  File "C:\Python3\lib\site-packages\docker\errors.py", line 31, in create_api_error_from_http_exception
    raise cls(e, response=response, explanation=explanation)
docker.errors.APIError: 500 Server Error: Internal Server Error ("Get https://111111111111.dkr.ecr.us-east-1.amazonaws.com/v2/my_repo/tags/list: no basic auth credentials")

What is the problem?问题是什么? Why I can not pull image even after client.login call which happens wihtout any exeptions.为什么即使在没有任何例外情况下发生的client.login调用之后我也无法拉取图像。 What is the correct way to perform login and pull image from ECR repository and dockerpy?从 ECR 存储库和 dockerpy 执行登录和拉取镜像的正确方法是什么?

This was happen due to - https://github.com/docker/docker-py/issues/2157这是由于 - https://github.com/docker/docker-py/issues/2157

Deleting ~/.docker/config.json fixed the issue.删除~/.docker/config.json修复了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker推送到AWS ECR在Windows上失败:没有基本身份验证凭据 - Docker push to AWS ECR fails on Windows: no basic auth credentials `无基本身份验证凭证` Github 到 AWS ECR 部署 git 事件 - `no basic auth credentials` Github to AWS ECR deployment on git events 将 docker 映像推送到 aws ecr 不会提供基本的身份验证凭据 - Pushing a docker image to aws ecr gives no basic auth credentials 尝试将docker-image资源推送到AWS ECR时使用“无基本身份验证凭证” - Concourse “no basic auth credentials” when trying to push with docker-image resource to AWS ECR 尝试从专用ECR提取图像时“没有基本身份验证凭据” - “no basic auth credentials” when trying to pull an image from a private ECR 无法将图像推送到 Amazon ECR - 因“没有基本身份验证凭证”而失败 - Can't push image to Amazon ECR - fails with "no basic auth credentials" 如何获取 Jenkins + ECR + Pipeline 的 AWS 凭证 - How to get AWS credentials for Jenkins + ECR + Pipeline AWS CDK - 如何有条件地创建 ECR 存储库 - AWS CDK - How do I create ECR repo conditionally AWS CLI 创建 ECR 存储库 - AWS CLI create ECR repo 无法将图像推送到 AWS Lambda - 因“没有基本身份验证凭证”而失败 - Can't push image to AWS Lambda - fails with "no basic auth credentials"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM