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