pythonpython-3.xdockerdjango-viewsdocker-api

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!


Solution

  • 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