简体   繁体   中英

Push docker image to Dockerhub using docker api python client

I'm working on docker api python client,I have successfully done with build image, but now I need to push that docker image to dockerhub repository.

Here's what I have tried:

From views.py

            client = docker.from_env()
            client.images.build(path=docker_folder, gzip=False, tag=deployment.name)
            image = client.images.get(deployment.name)
            print(image.short_id)
            print("start pushing your docker image to docker hub")
            auth_config = {
                'username': '***dockerhub-email ***',
                'password': '***Password***',
            }
            client.images.push('arycloud/istiogui', tag=deployment.name,
                               auth_config=auth_config)

it doesn't return any error but image not pushed on docker hub reporitoy. Here's the repository I'm using:

https://hub.docker.com/r/arycloud/istiogui/

Updated code after @Tarun's comments

            client = docker.from_env()
            print("Start Building your docker image...")
            client.images.build(path=docker_folder, gzip=False, tag=deployment.name)
            image = client.images.get(deployment.name)
            print(image.short_id)
            print("start pushing your docker image to docker hub")
            client.login(username='***', password='***')
            client.images.push('arycloud/istiogui', tag=deployment.name)

after that still my image doesn't pushed on dockerhub!

You can try this

client.login(username='***', password='***')
for line in client.images.push('arycloud/istiogui', stream=True, decode=True):
    print(line)

it will print the output which is basically the error or success info

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM