Import an image. Similar to the ``docker import`` command. If ``src`` is a string or unicode string, it will first be treated as a path to a tarball on the local system. If there is an error reading from that file, ``src`` will be treated as a URL instead to fetch t
(self, src=None, repository=None, tag=None, image=None,
changes=None, stream_src=False)
| 100 | return res |
| 101 | |
| 102 | def import_image(self, src=None, repository=None, tag=None, image=None, |
| 103 | changes=None, stream_src=False): |
| 104 | """ |
| 105 | Import an image. Similar to the ``docker import`` command. |
| 106 | |
| 107 | If ``src`` is a string or unicode string, it will first be treated as a |
| 108 | path to a tarball on the local system. If there is an error reading |
| 109 | from that file, ``src`` will be treated as a URL instead to fetch the |
| 110 | image from. You can also pass an open file handle as ``src``, in which |
| 111 | case the data will be read from that file. |
| 112 | |
| 113 | If ``src`` is unset but ``image`` is set, the ``image`` parameter will |
| 114 | be taken as the name of an existing image to import from. |
| 115 | |
| 116 | Args: |
| 117 | src (str or file): Path to tarfile, URL, or file-like object |
| 118 | repository (str): The repository to create |
| 119 | tag (str): The tag to apply |
| 120 | image (str): Use another image like the ``FROM`` Dockerfile |
| 121 | parameter |
| 122 | """ |
| 123 | if not (src or image): |
| 124 | raise errors.DockerException( |
| 125 | 'Must specify src or image to import from' |
| 126 | ) |
| 127 | u = self._url('/images/create') |
| 128 | |
| 129 | params = _import_image_params( |
| 130 | repository, tag, image, |
| 131 | src=(src if isinstance(src, str) else None), |
| 132 | changes=changes |
| 133 | ) |
| 134 | headers = {'Content-Type': 'application/tar'} |
| 135 | |
| 136 | if image or params.get('fromSrc') != '-': # from image or URL |
| 137 | return self._result( |
| 138 | self._post(u, data=None, params=params) |
| 139 | ) |
| 140 | elif isinstance(src, str): # from file path |
| 141 | with open(src, 'rb') as f: |
| 142 | return self._result( |
| 143 | self._post( |
| 144 | u, data=f, params=params, headers=headers, timeout=None |
| 145 | ) |
| 146 | ) |
| 147 | else: # from raw data |
| 148 | if stream_src: |
| 149 | headers['Transfer-Encoding'] = 'chunked' |
| 150 | return self._result( |
| 151 | self._post(u, data=src, params=params, headers=headers) |
| 152 | ) |
| 153 | |
| 154 | def import_image_from_data(self, data, repository=None, tag=None, |
| 155 | changes=None): |