Natjo
Natjo

Reputation: 2118

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. 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. How can I achieve the behaviour of this flag through Python? Am I missing something?

Upvotes: 0

Views: 451

Answers (1)

Natjo
Natjo

Reputation: 2118

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:

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')

Upvotes: 1

Related Questions