[英]Create docker service with image from private registry through python library
I use the Docker SDK for Python to start a service on docker Swarm.我使用Docker SDK 为 Python 在 Z05B6053C41A2130AFD6BFCDA3上启动服务。 The image I require is on a private registry.
我需要的图像位于私有注册表中。 I would use the
--with-registry-auth
flag for the docker cli , but it seems it does not exist in the Python module.我会为docker cli使用
--with-registry-auth
标志,但它似乎在 Python 模块中不存在。 How can I achieve the behaviour of this flag through Python?如何通过 Python 实现这个标志的行为? Am I missing something?
我错过了什么吗?
I figured it out, and luckily it is quite easy.我想通了,幸运的是这很容易。 You simply need to login with the client object in use: After that it will automatically use the private registry if required:
您只需使用正在使用的客户端 object 登录:之后,如果需要,它将自动使用私有注册表:
import docker
# Create client and login
client = docker.DockerClient(base_url='unix://var/run/docker.sock')
client.login(
username=USERNAME,
password=PASSWORD,
registry=REGISTRY_URL
)
# Define service
service_id = client.services.create(image=IMAGE_NAME, command=None, name='test')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.