Home > Back-end >  Get the size of an image using the Docker SDK for Python
Get the size of an image using the Docker SDK for Python

Time:11-13

How do I get the size of a docker image using the Docker SDK for Python?

import docker
client = docker.from_env()
some_image : docker.models.images.Image = client.images.list()[0]
# size of some_image?

As specified here, the regular docker API has some differences when getting the size from a registry or locally. I'll take either one.

CodePudding user response:

The size is listed in "attrs" json of the image.

import docker
client = docker.from_env()
some_image : docker.models.images.Image = client.images.list()[0]
some_image.attrs['Size'] # size in Bytes. 
  • Related