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

Viewed 7231

I am trying to use the Docker Python API to login to a Docker cloud:

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

What is the 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.

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:

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.

Can you give me an example that works?

3 Answers

Here's how I have logged in to Docker using Python:

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.

Related