简体   繁体   English

通过 python 库使用来自私有注册表的图像创建 docker 服务

[英]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.

相关问题 将私有库安装到 python docker 映像 - Install private library to python docker image 为 Autoplotter Python 库创建 Docker 服务 - Create Docker Service for Autoplotter Python Library 使用 Docker Registry API 客户端在 Docker Hub 上创建私有存储库 - Create a private repository on Docker Hub using Docker Registry API Client 如何使用 Airflow 2.0 中的 DockerOperator 从 GitLab 容器注册表中提取私有 docker 映像? - How to pull private docker image from GitLab container registry using DockerOperator in Airflow 2.0? 使用 Docker API for Python 在 Google Container Registry 中标记图像 - Tag image in Google Container Registry with Docker API for Python Install a python package using pip from private GitHub repo when building Docker image? - Install a python package using pip from private GitHub repo when building Docker image? 循环通过Registry Python - Loop through Registry Python 如何在 Docker Python 映像中安装 GDAL 库? - How to install GDAL Library in Docker Python image? 如何在拉出的docker映像上安装python库? - How to install a python library to a pulled docker image? 如何从 Python 访问谷歌云 docker 注册表 - How to access google cloud docker registry from Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM