diff --git a/docker/api/build.py b/docker/api/build.py index e136a6ee..3067c105 100644 --- a/docker/api/build.py +++ b/docker/api/build.py @@ -18,7 +18,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, platform=None): + squash=None, extra_hosts=None, platform=None, isolation=None): """ Similar to the ``docker build`` command. Either ``path`` or ``fileobj`` needs to be set. ``path`` can be a local path (to a directory @@ -100,6 +100,8 @@ class BuildApiMixin(object): 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]]`` + isolation (str): Isolation technology used during build. + Default: `None`. Returns: A generator for the build output. @@ -232,6 +234,13 @@ class BuildApiMixin(object): ) params['platform'] = platform + if isolation is not None: + if utils.version_lt(self._version, '1.24'): + raise errors.InvalidVersion( + 'isolation was only introduced in API version 1.24' + ) + params['isolation'] = isolation + if context is not None: headers = {'Content-Type': 'application/tar'} if encoding: diff --git a/docker/models/images.py b/docker/models/images.py index d4c28132..bb24eb5c 100644 --- a/docker/models/images.py +++ b/docker/models/images.py @@ -164,6 +164,8 @@ class ImageCollection(Collection): 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]]``. + isolation (str): Isolation technology used during build. + Default: `None`. Returns: (tuple): The first item is the :py:class:`Image` object for the diff --git a/tests/integration/api_build_test.py b/tests/integration/api_build_test.py index ce587d54..13bd8ac5 100644 --- a/tests/integration/api_build_test.py +++ b/tests/integration/api_build_test.py @@ -138,6 +138,21 @@ class BuildTest(BaseAPIIntegrationTest): # There is currently no way to get the shmsize # that was used to build the image + @requires_api_version('1.24') + def test_build_isolation(self): + script = io.BytesIO('\n'.join([ + 'FROM scratch', + 'CMD sh -c "echo \'Deaf To All But The Song\'' + ]).encode('ascii')) + + stream = self.client.build( + fileobj=script, tag='isolation', + isolation='default' + ) + + for chunk in stream: + pass + @requires_api_version('1.23') def test_build_labels(self): script = io.BytesIO('\n'.join([