@@ -395,12 +395,12 @@ def load(self, data):
395
395
396
396
return [self .get (i ) for i in images ]
397
397
398
- def pull (self , repository , tag = None , ** kwargs ):
398
+ def pull (self , repository , tag = None , all_tags = False , ** kwargs ):
399
399
"""
400
400
Pull an image of the given name and return it. Similar to the
401
401
``docker pull`` command.
402
- If no tag is specified, all tags from that repository will be
403
- pulled.
402
+ If ``all_tags`` is set, the ``tag`` parameter is ignored and all image
403
+ tags will be pulled.
404
404
405
405
If you want to get the raw pull output, use the
406
406
:py:meth:`~docker.api.image.ImageApiMixin.pull` method in the
@@ -413,10 +413,11 @@ def pull(self, repository, tag=None, **kwargs):
413
413
config for this request. ``auth_config`` should contain the
414
414
``username`` and ``password`` keys to be valid.
415
415
platform (str): Platform in the format ``os[/arch[/variant]]``
416
+ all_tags (bool): Pull all image tags
416
417
417
418
Returns:
418
419
(:py:class:`Image` or list): The image that has been pulled.
419
- If no ``tag`` was specified , the method will return a list
420
+ If ``tag`` is None , the method will return a list
420
421
of :py:class:`Image` objects belonging to this repository.
421
422
422
423
Raises:
@@ -426,13 +427,13 @@ def pull(self, repository, tag=None, **kwargs):
426
427
Example:
427
428
428
429
>>> # Pull the image tagged `latest` in the busybox repo
429
- >>> image = client.images.pull('busybox:latest ')
430
+ >>> image = client.images.pull('busybox')
430
431
431
432
>>> # Pull all tags in the busybox repo
432
- >>> images = client.images.pull('busybox')
433
+ >>> images = client.images.pull('busybox', all_tags=True )
433
434
"""
434
- if not tag :
435
- repository , tag = parse_repository_tag ( repository )
435
+ repository , image_tag = parse_repository_tag ( repository )
436
+ tag = tag or image_tag or 'latest'
436
437
437
438
if 'stream' in kwargs :
438
439
warnings .warn (
@@ -442,14 +443,14 @@ def pull(self, repository, tag=None, **kwargs):
442
443
del kwargs ['stream' ]
443
444
444
445
pull_log = self .client .api .pull (
445
- repository , tag = tag , stream = True , ** kwargs
446
+ repository , tag = tag , stream = True , all_tags = all_tags , ** kwargs
446
447
)
447
448
for _ in pull_log :
448
449
# We don't do anything with the logs, but we need
449
450
# to keep the connection alive and wait for the image
450
451
# to be pulled.
451
452
pass
452
- if tag :
453
+ if not all_tags :
453
454
return self .get ('{0}{2}{1}' .format (
454
455
repository , tag , '@' if tag .startswith ('sha256:' ) else ':'
455
456
))
0 commit comments