Open vincenthcui opened 6 years ago
http://docker-py.readthedocs.io/en/stable/images.html#docker.models.images.ImageCollection.push
decode (bool) – Decode the JSON data from the server into dicts. Only applies with
stream=True
Thanks for quick response. And I think I don't express my meanings clearly :(
What I want is to get meanings from every line of those response, instead of how to format json data. For examples, how many kinds of status need to be process correctly, or how many fields in those lines.
Thank you!
@vincenthcui This may be too late for you, but here is an example of how i use the pull statuses:
def extract_progress_info(line):
"""
Extract progress information from a Docker Pull progress object
:param line: Docker pull progress object (Json)
:return: Transoformed progress object (Json)
"""
# Extract pieces of interest
pid = line['id'] if 'id' in line else ""
status = line['status'] if 'status' in line else ""
progress_detail = line['progressDetail'] if 'progressDetail' in line else {}
complete_statuses = ['Download complete', 'Pull complete', 'Already exists', 'Layer already exists', 'Pushed']
percent = 0
if status in complete_statuses:
percent = 100
elif progress_detail != {}:
current = line['progressDetail']['current']
total = line['progressDetail']['total']
percent = round((current / total) * 100)
# Create progress object
progress = {'id': pid, 'status': status, 'percent': percent}
return progress
The input to this function is decoded as @shin- alluded above.
@astrocaribe Have you ever noticed that current
ends up being a larger value than total
? I've been chasing my tail trying to figure out why I'm always ending up at like 102% complete but the docker API docs are not very helpful. https://docs.docker.com/reference/api/engine/version/v1.47/#tag/Image/operation/ImagePush
Example output from my version of your code above:
Status: Pushing, ID: 2b2b3410e106, Progress: 517843456/509753187
I use
client.images.push(repository, stream=True)
api to push docker image to remote registry, and get response just likeand now I want to parse those json response to know if the push action is success or not, but find no reference in either docker-py docs nor docker api docs.
so, how can I parse and hadle image push response correctly?
Thx!