简体   繁体   English

使用Docker Python SDK登录注册表(docker-py)

[英]Login to registry with Docker Python SDK (docker-py)

I am trying to use the Docker Python API to login to a Docker cloud: 我正在尝试使用Docker Python API登录Docker云:

https://docker-py.readthedocs.io/en/stable/client.html#creating-a-client1 https://docker-py.readthedocs.io/en/stable/client.html#creating-a-client1

What is the URL? 什么是URL? What is the Port? 什么是港口?

I have tried to get it to work with cloud.docker.com, but I am fine with any registry server, so long as it is free to use and I can use it to upload Docker images from one computer and run them on another. 我试图让它与cloud.docker.com一起工作,但我对任何注册服务器都没问题,只要它可以免费使用,我可以用它从一台计算机上传Docker镜像并在另一台计算机上运行它们。

I have already got everything running using my own locally hosted registry, but I can't seem to figure out how to connect to a server. 我已经使用我自己的本地托管注册表运行所有内容,但我似乎无法弄清楚如何连接到服务器。 It's kind of ridiculous that hosting my own registry is easier than using an existing registry server. 托管我自己的注册表比使用现有的注册表服务器更容易,这有点荒谬。

My code looks like this, but I am unsure what the args.* parameters should be: 我的代码看起来像这样,但我不确定args。*参数应该是什么:

client = docker.DockerClient(base_url=args.docker_registry)
client.login(username=args.docker_user, password=args.docker_password)

I'm not sure what the base_url needs to be so that I can log in, and the error messages are not helpful at all. 我不确定base_url需要什么,以便我可以登录,并且错误消息根本没有帮助。

Can you give me an example that works? 你能给我一个有效的例子吗?

The base_url parameter is the URL of the Docker server, not the Docker Registry. base_url参数是Docker服务器的URL,而不是Docker Registry。

Try something like: 尝试类似的东西:

from docker.errors import APIError, TLSParameterError

try:
   client = docker.from_env()
   client.login(username=args.docker_user, password=args.docker_password, registry=args.docker_registry)
except (APIError, TLSParameterError) as err:
   # ...

Here's how I have logged in to Docker using Python: 以下是我使用Python登录Docker的方法:

import docker

client = docker.from_env()
client.login(username='USERNAME', password='PASSWORD', email='EMAIL',
                       registry='https://index.docker.io/v1/')

and here's what it returns: 这是它的回报:

{'IdentityToken': '', 'Status': 'Login Succeeded'}

So, that means it has been logged in successfully. 所以,这意味着它已成功登录。

我仍然没有弄清楚cloud.docker.com的注册表被调用了什么,但我通过切换到quay.io作为我的注册表服务器来工作,它使用直观的注册表='quay.io'

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

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