通过 python 库使用私有注册表中的图像创建 docker 服务
Create docker service with image from private registry through python library
我用的是Docker SDK for Python to start a service on docker Swarm. The image I require is on a private registry. I would use the --with-registry-auth
flag for the docker cli,但是Python模块里好像没有。如何通过 Python 实现此标志的行为?我错过了什么吗?
我想通了,幸运的是它很容易!您只需使用正在使用的客户端对象登录即可。之后它将根据需要自动使用私有注册表:
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')
我用的是Docker SDK for Python to start a service on docker Swarm. The image I require is on a private registry. I would use the --with-registry-auth
flag for the docker cli,但是Python模块里好像没有。如何通过 Python 实现此标志的行为?我错过了什么吗?
我想通了,幸运的是它很容易!您只需使用正在使用的客户端对象登录即可。之后它将根据需要自动使用私有注册表:
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')