Get a tarball of an image. Similar to the ``docker save`` command. Args: chunk_size (int): The generator will return up to that much data per iteration, but may return less. If ``None``, data will be streamed as it is received. Default: 2
(self, chunk_size=DEFAULT_DATA_CHUNK_SIZE, named=False)
| 78 | ) |
| 79 | |
| 80 | def save(self, chunk_size=DEFAULT_DATA_CHUNK_SIZE, named=False): |
| 81 | """ |
| 82 | Get a tarball of an image. Similar to the ``docker save`` command. |
| 83 | |
| 84 | Args: |
| 85 | chunk_size (int): The generator will return up to that much data |
| 86 | per iteration, but may return less. If ``None``, data will be |
| 87 | streamed as it is received. Default: 2 MB |
| 88 | named (str or bool): If ``False`` (default), the tarball will not |
| 89 | retain repository and tag information for this image. If set |
| 90 | to ``True``, the first tag in the :py:attr:`~tags` list will |
| 91 | be used to identify the image. Alternatively, any element of |
| 92 | the :py:attr:`~tags` list can be used as an argument to use |
| 93 | that specific tag as the saved identifier. |
| 94 | |
| 95 | Returns: |
| 96 | (generator): A stream of raw archive data. |
| 97 | |
| 98 | Raises: |
| 99 | :py:class:`docker.errors.APIError` |
| 100 | If the server returns an error. |
| 101 | |
| 102 | Example: |
| 103 | |
| 104 | >>> image = cli.images.get("busybox:latest") |
| 105 | >>> f = open('/tmp/busybox-latest.tar', 'wb') |
| 106 | >>> for chunk in image.save(): |
| 107 | >>> f.write(chunk) |
| 108 | >>> f.close() |
| 109 | """ |
| 110 | img = self.id |
| 111 | if named: |
| 112 | img = self.tags[0] if self.tags else img |
| 113 | if isinstance(named, str): |
| 114 | if named not in self.tags: |
| 115 | raise InvalidArgument( |
| 116 | f"{named} is not a valid tag for this image" |
| 117 | ) |
| 118 | img = named |
| 119 | |
| 120 | return self.client.api.get_image(img, chunk_size) |
| 121 | |
| 122 | def tag(self, repository, tag=None, **kwargs): |
| 123 | """ |