Clivern / Kraven

:white_flower: A SaaS docker management dashboard to manage your docker containers, images, volumes, networks and much more!
Apache License 2.0
7 stars 1 forks source link

Interactive Commands & Low Level API #28

Open Clivern opened 6 years ago

Clivern commented 6 years ago
https://docker-py.readthedocs.io/en/stable/api.html#module-docker.api.build
from docker import APIClient

cli = APIClient(base_url='tcp://127.0.0.1:4243')
for line in cli.pull('ubuntu:latest', stream=True):
     print(line)
Clivern commented 6 years ago
import json
from docker import APIClient

cli = APIClient(base_url='tcp://127.0.0.1:4243')
for line in cli.pull('python:3.4-alpine', stream=True):
    print(__pretty_response(line))

def __pretty_response(line):
        result = ""
        line = json.loads(line)

        if "id" in line:
            result += "%s: " % str(line["id"])

        if "status" in line:
            result += "%s" % str(line["status"])

        if "progress" in line:
            result += "                %s" % str(line["progress"])

        return result
3.4-alpine: Pulling from library/python
8e3ba11ec2a2: Already exists
4001a9c615cb: Pulling fs layer
5bbb3a9b8d5e: Pulling fs layer
5adcac484e5a: Pulling fs layer
ffd089d04f72: Pulling fs layer
ffd089d04f72: Waiting
4001a9c615cb: Downloading                [>                                                  ]  4.434kB/309kB
4001a9c615cb: Downloading                [==================================================>]    309kB/309kB
4001a9c615cb: Verifying Checksum
4001a9c615cb: Download complete
4001a9c615cb: Extracting                [=====>                                             ]  32.77kB/309kB
5adcac484e5a: Downloading                [==================================================>]     230B/230B
5adcac484e5a: Verifying Checksum
5adcac484e5a: Download complete
5bbb3a9b8d5e: Downloading                [>                                                  ]  212.5kB/21.09MB
4001a9c615cb: Extracting                [==================================================>]    309kB/309kB
4001a9c615cb: Extracting                [==================================================>]    309kB/309kB
4001a9c615cb: Pull complete
5bbb3a9b8d5e: Downloading                [============================>                      ]  11.98MB/21.09MB
5bbb3a9b8d5e: Verifying Checksum
5bbb3a9b8d5e: Download complete
5bbb3a9b8d5e: Extracting                [>                                                  ]  229.4kB/21.09MB
5bbb3a9b8d5e: Extracting                [====>                                              ]  1.835MB/21.09MB
ffd089d04f72: Downloading                [>                                                  ]  18.28kB/1.789MB
ffd089d04f72: Verifying Checksum
ffd089d04f72: Download complete
5bbb3a9b8d5e: Extracting                [========>                                          ]   3.67MB/21.09MB
5bbb3a9b8d5e: Extracting                [============>                                      ]  5.276MB/21.09MB
5bbb3a9b8d5e: Extracting                [=================>                                 ]  7.569MB/21.09MB
5bbb3a9b8d5e: Extracting                [======================>                            ]  9.634MB/21.09MB
5bbb3a9b8d5e: Extracting                [===========================>                       ]   11.7MB/21.09MB
5bbb3a9b8d5e: Extracting                [=================================>                 ]  13.99MB/21.09MB
5bbb3a9b8d5e: Extracting                [====================================>              ]   15.6MB/21.09MB
5bbb3a9b8d5e: Extracting                [========================================>          ]   17.2MB/21.09MB
5bbb3a9b8d5e: Extracting                [============================================>      ]  18.58MB/21.09MB
5bbb3a9b8d5e: Extracting                [==============================================>    ]   19.5MB/21.09MB
5bbb3a9b8d5e: Extracting                [==============================================>    ]  19.73MB/21.09MB
5bbb3a9b8d5e: Extracting                [==================================================>]  21.09MB/21.09MB
5bbb3a9b8d5e: Pull complete
5adcac484e5a: Extracting                [==================================================>]     230B/230B
5adcac484e5a: Extracting                [==================================================>]     230B/230B
5adcac484e5a: Pull complete
ffd089d04f72: Extracting                [>                                                  ]  32.77kB/1.789MB
ffd089d04f72: Extracting                [=====================>                             ]  753.7kB/1.789MB
ffd089d04f72: Extracting                [==================================================>]  1.789MB/1.789MB
ffd089d04f72: Pull complete
Digest: sha256:9ecfc28113e3e0299e82fbfbbf37851b9c84efbf931eae22ccd69d2ad1562c91
Status: Downloaded newer image for python:3.4-alpine
Clivern commented 6 years ago

Finally how the low level api works

from app.modules.service.docker.low_level.image import Image

_image = Image(5)
if _image.check_health("api_client"):
     for line in _image.pull("php", "latest"):
          print(_image._pretty_response(line))
latest: Pulling from library/php
be8881be8156: Already exists
69a25f7e4930: Already exists
65632e89c5f4: Already exists
cd75fa32da8f: Already exists
df40abb485c8: Pulling fs layer
ef9b64f91b97: Pulling fs layer
a8b97be65d64: Pulling fs layer
66e26344c777: Pulling fs layer
aefd38ccf5b1: Pulling fs layer
66e26344c777: Waiting
aefd38ccf5b1: Waiting
ef9b64f91b97: Downloading                    [=================================>                 ]     330B/499B
ef9b64f91b97: Downloading                    [==================================================>]     499B/499B
ef9b64f91b97: Verifying Checksum
ef9b64f91b97: Download complete
df40abb485c8: Downloading                    [>                                                  ]  126.9kB/12.46MB
a8b97be65d64: Downloading                    [>                                                  ]  301.8kB/28.61MB
df40abb485c8: Downloading                    [=================================================> ]  12.37MB/12.46MB
df40abb485c8: Verifying Checksum
df40abb485c8: Download complete
df40abb485c8: Extracting                    [>                                                  ]  131.1kB/12.46MB
a8b97be65d64: Downloading                    [============>                                      ]  7.265MB/28.61MB
df40abb485c8: Extracting                    [==================================================>]  12.46MB/12.46MB
a8b97be65d64: Downloading                    [===============================>                   ]  17.79MB/28.61MB
df40abb485c8: Pull complete
ef9b64f91b97: Extracting                    [==================================================>]     499B/499B
ef9b64f91b97: Extracting                    [==================================================>]     499B/499B
66e26344c777: Downloading                    [=======>                                           ]     329B/2.181kB
66e26344c777: Downloading                    [==================================================>]  2.181kB/2.181kB
66e26344c777: Verifying Checksum
66e26344c777: Download complete
ef9b64f91b97: Pull complete
a8b97be65d64: Downloading                    [============================================>      ]  25.71MB/28.61MB
a8b97be65d64: Verifying Checksum
a8b97be65d64: Download complete
a8b97be65d64: Extracting                    [>                                                  ]  294.9kB/28.61MB
a8b97be65d64: Extracting                    [====>                                              ]  2.654MB/28.61MB
aefd38ccf5b1: Downloading                    [==================================================>]     263B/263B
aefd38ccf5b1: Verifying Checksum
aefd38ccf5b1: Download complete
a8b97be65d64: Extracting                    [========>                                          ]  4.719MB/28.61MB
a8b97be65d64: Extracting                    [============>                                      ]  7.373MB/28.61MB
a8b97be65d64: Extracting                    [================>                                  ]  9.437MB/28.61MB
a8b97be65d64: Extracting                    [====================>                              ]   11.5MB/28.61MB
a8b97be65d64: Extracting                    [=======================>                           ]  13.57MB/28.61MB
a8b97be65d64: Extracting                    [===========================>                       ]  15.63MB/28.61MB
a8b97be65d64: Extracting                    [=============================>                     ]   17.1MB/28.61MB
a8b97be65d64: Extracting                    [=================================>                 ]  19.17MB/28.61MB
a8b97be65d64: Extracting                    [=====================================>             ]  21.23MB/28.61MB
a8b97be65d64: Extracting                    [========================================>          ]   23.3MB/28.61MB
a8b97be65d64: Extracting                    [============================================>      ]  25.36MB/28.61MB
a8b97be65d64: Extracting                    [==============================================>    ]  26.84MB/28.61MB
a8b97be65d64: Extracting                    [================================================>  ]  27.72MB/28.61MB
a8b97be65d64: Extracting                    [==================================================>]  28.61MB/28.61MB
a8b97be65d64: Pull complete
66e26344c777: Extracting                    [==================================================>]  2.181kB/2.181kB
66e26344c777: Extracting                    [==================================================>]  2.181kB/2.181kB
66e26344c777: Pull complete
aefd38ccf5b1: Extracting                    [==================================================>]     263B/263B
aefd38ccf5b1: Extracting                    [==================================================>]     263B/263B
aefd38ccf5b1: Pull complete
Digest: sha256:32db09e979db3aea2a2a320980cbcceab310e0320b045df8306ade15d52624b1
Status: Downloaded newer image for php:latest
latest: Pulling from library/php
Digest: sha256:32db09e979db3aea2a2a320980cbcceab310e0320b045df8306ade15d52624b1
Status: Image is up to date for php:latest