Docker-py: correct way to push image to a private repository

Created on 6 Aug 2018  路  3Comments  路  Source: docker/docker-py

I'm having problem to push image to our private repository, and I'm a bit confused about different login() method and auth parameter.
where should I set the url of my private repository?
I have this and it's not working:

client.api.base_url = 'https://registry.example.com'
auth = {
            'username': registry_configs['USERNAME'],
            'password': registry_configs['PASSWORD']
        }
client.api.push("someuser/some-image", tag="v2", stream=True, auth_config=auth)

it will results in lots of

{"status":"Preparing","progressDetail":{},"id":"735ec19c63e8"}

and

{"status":"Waiting","progressDetail":{},"id":"735ec19c63e8"}

while I'm sure my username/password is correct (I checked it with docker cli) but at the end it will output:

{"errorDetail":{"message":"unauthorized: incorrect username or password"},"error":"unauthorized: incorrect username or password"}

what did I wrong?

Most helpful comment

Something like this:

import os.path

import docker

registry_url = 'registry.example.com'
img_name = 'someuser/some-image'

client = docker.from_env()
img = client.images.get(img_name)
assert img.tag(os.path.join(registry_url, img_name))
client.login(
  username=registry_configs['USERNAME'],
  password=registry_config['PASSWORD'],
  registry=registry_url
)
client.images.push(os.path.join(registry_url, img_name))

All 3 comments

Something like this:

import os.path

import docker

registry_url = 'registry.example.com'
img_name = 'someuser/some-image'

client = docker.from_env()
img = client.images.get(img_name)
assert img.tag(os.path.join(registry_url, img_name))
client.login(
  username=registry_configs['USERNAME'],
  password=registry_config['PASSWORD'],
  registry=registry_url
)
client.images.push(os.path.join(registry_url, img_name))

Thank you @shin- works great

Not sure but https://github.com/docker/docker-py/issues/2104#issuecomment-410802929 fails with the following:

  File "/usr/local/lib/python3.8/dist-packages/docker/client.py", line 221, in __getattr__
    raise AttributeError(' '.join(s))
AttributeError: 'DockerClient' object has no attribute 'push' In Docker SDK for Python 2.0, this method is now on the object APIClient. See the low-level API section of the documentation for more details.
$ pip3 show docker
Name: docker
Version: 4.4.1
Was this page helpful?
0 / 5 - 0 ratings