简体   繁体   中英

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

I m trying to execute the folowing python code:

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. What is the correct way to perform login and pull image from ECR repository and dockerpy?

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

Deleting ~/.docker/config.json fixed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM