diff options
Diffstat (limited to 'docker')
-rw-r--r-- | docker/api/build.py | 10 | ||||
-rw-r--r-- | docker/api/image.py | 13 | ||||
-rw-r--r-- | docker/models/containers.py | 8 | ||||
-rw-r--r-- | docker/models/images.py | 2 |
4 files changed, 28 insertions, 5 deletions
diff --git a/docker/api/build.py b/docker/api/build.py index 34456ab..32238ef 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -19,7 +19,7 @@ class BuildApiMixin(object): forcerm=False, dockerfile=None, container_limits=None, decode=False, buildargs=None, gzip=False, shmsize=None, labels=None, cache_from=None, target=None, network_mode=None, - squash=None, extra_hosts=None): + squash=None, extra_hosts=None, platform=None): """ Similar to the ``docker build`` command. Either ``path`` or ``fileobj`` needs to be set. ``path`` can be a local path (to a directory @@ -103,6 +103,7 @@ class BuildApiMixin(object): single layer. extra_hosts (dict): Extra hosts to add to /etc/hosts in building containers, as a mapping of hostname to IP address. + platform (str): Platform in the format ``os[/arch[/variant]]`` Returns: A generator for the build output. @@ -243,6 +244,13 @@ class BuildApiMixin(object): extra_hosts = utils.format_extra_hosts(extra_hosts) params.update({'extrahosts': extra_hosts}) + if platform is not None: + if utils.version_lt(self._version, '1.32'): + raise errors.InvalidVersion( + 'platform was only introduced in API version 1.32' + ) + params['platform'] = platform + if context is not None: headers = {'Content-Type': 'application/tar'} if encoding: diff --git a/docker/api/image.py b/docker/api/image.py index 7755312..065fae3 100644 --- a/docker/api/image.py +++ b/docker/api/image.py @@ -323,7 +323,8 @@ class ImageApiMixin(object): return self._result(self._post(url, params=params), True) def pull(self, repository, tag=None, stream=False, - insecure_registry=False, auth_config=None, decode=False): + insecure_registry=False, auth_config=None, decode=False, + platform=None): """ Pulls an image. Similar to the ``docker pull`` command. @@ -336,6 +337,7 @@ class ImageApiMixin(object): :py:meth:`~docker.api.daemon.DaemonApiMixin.login` has set for this request. ``auth_config`` should contain the ``username`` and ``password`` keys to be valid. + platform (str): Platform in the format ``os[/arch[/variant]]`` Returns: (generator or str): The output @@ -376,7 +378,7 @@ class ImageApiMixin(object): } headers = {} - if utils.compare_version('1.5', self._version) >= 0: + if utils.version_gte(self._version, '1.5'): if auth_config is None: header = auth.get_config_header(self, registry) if header: @@ -385,6 +387,13 @@ class ImageApiMixin(object): log.debug('Sending supplied auth config') headers['X-Registry-Auth'] = auth.encode_header(auth_config) + if platform is not None: + if utils.version_lt(self._version, '1.32'): + raise errors.InvalidVersion( + 'platform was only introduced in API version 1.32' + ) + params['platform'] = platform + response = self._post( self._url('/images/create'), params=params, headers=headers, stream=stream, timeout=None diff --git a/docker/models/containers.py b/docker/models/containers.py index 6ba308e..5e2aa88 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -579,6 +579,8 @@ class ContainerCollection(Collection): inside the container. pids_limit (int): Tune a container's pids limit. Set ``-1`` for unlimited. + platform (str): Platform in the format ``os[/arch[/variant]]``. + Only used if the method needs to pull the requested image. ports (dict): Ports to bind inside the container. The keys of the dictionary are the ports to bind inside the @@ -700,7 +702,9 @@ class ContainerCollection(Collection): if isinstance(image, Image): image = image.id stream = kwargs.pop('stream', False) - detach = kwargs.pop("detach", False) + detach = kwargs.pop('detach', False) + platform = kwargs.pop('platform', None) + if detach and remove: if version_gte(self.client.api._version, '1.25'): kwargs["auto_remove"] = True @@ -718,7 +722,7 @@ class ContainerCollection(Collection): container = self.create(image=image, command=command, detach=detach, **kwargs) except ImageNotFound: - self.client.images.pull(image) + self.client.images.pull(image, platform=platform) container = self.create(image=image, command=command, detach=detach, **kwargs) diff --git a/docker/models/images.py b/docker/models/images.py index 82ca541..891c565 100644 --- a/docker/models/images.py +++ b/docker/models/images.py @@ -157,6 +157,7 @@ class ImageCollection(Collection): single layer. extra_hosts (dict): Extra hosts to add to /etc/hosts in building containers, as a mapping of hostname to IP address. + platform (str): Platform in the format ``os[/arch[/variant]]``. Returns: (:py:class:`Image`): The built image. @@ -265,6 +266,7 @@ class ImageCollection(Collection): :py:meth:`~docker.client.DockerClient.login` has set for this request. ``auth_config`` should contain the ``username`` and ``password`` keys to be valid. + platform (str): Platform in the format ``os[/arch[/variant]]`` Returns: (:py:class:`Image`): The image that has been pulled. |