diff --git a/docker/api/container.py b/docker/api/container.py index 7aeea202..97a39b65 100644 --- a/docker/api/container.py +++ b/docker/api/container.py @@ -238,7 +238,7 @@ class ContainerApiMixin(object): memswap_limit=None, cpuset=None, host_config=None, mac_address=None, labels=None, volume_driver=None, stop_signal=None, networking_config=None, - healthcheck=None, stop_timeout=None): + healthcheck=None, stop_timeout=None, runtime=None): """ Creates a container. Parameters are similar to those for the ``docker run`` command except it doesn't support the attach options (``-a``). @@ -417,6 +417,7 @@ class ContainerApiMixin(object): Default: 10 networking_config (dict): A networking configuration generated by :py:meth:`create_networking_config`. + runtime (str): Runtime to use with this container. Returns: A dictionary with an image 'Id' key and a 'Warnings' key. @@ -441,7 +442,7 @@ class ContainerApiMixin(object): network_disabled, entrypoint, cpu_shares, working_dir, domainname, memswap_limit, cpuset, host_config, mac_address, labels, volume_driver, stop_signal, networking_config, healthcheck, - stop_timeout + stop_timeout, runtime ) return self.create_container_from_config(config, name) @@ -576,6 +577,7 @@ class ContainerApiMixin(object): values are: ``host`` volumes_from (:py:class:`list`): List of container names or IDs to get volumes from. + runtime (str): Runtime to use with this container. Returns: diff --git a/docker/models/containers.py b/docker/models/containers.py index 4bb2cf86..300c5a9d 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -659,6 +659,7 @@ class ContainerCollection(Collection): volumes_from (:py:class:`list`): List of container names or IDs to get volumes from. working_dir (str): Path to the working directory. + runtime (str): Runtime to use with this container. Returns: The container logs, either ``STDOUT``, ``STDERR``, or both, @@ -885,6 +886,7 @@ RUN_HOST_CONFIG_KWARGS = [ 'userns_mode', 'version', 'volumes_from', + 'runtime' ] diff --git a/docker/types/containers.py b/docker/types/containers.py index f33c5e83..6bbb57ae 100644 --- a/docker/types/containers.py +++ b/docker/types/containers.py @@ -120,7 +120,7 @@ class HostConfig(dict): isolation=None, auto_remove=False, storage_opt=None, init=None, init_path=None, volume_driver=None, cpu_count=None, cpu_percent=None, nano_cpus=None, - cpuset_mems=None): + cpuset_mems=None, runtime=None): if mem_limit is not None: self['Memory'] = parse_bytes(mem_limit) @@ -473,6 +473,11 @@ class HostConfig(dict): self['NanoCpus'] = nano_cpus + if runtime: + if version_lt(version, '1.25'): + raise host_config_version_error('runtime', '1.25') + self['Runtime'] = runtime + def host_config_type_error(param, param_value, expected): error_msg = 'Invalid type for {0} param: expected {1} but found {2}' @@ -499,7 +504,7 @@ class ContainerConfig(dict): working_dir=None, domainname=None, memswap_limit=None, cpuset=None, host_config=None, mac_address=None, labels=None, volume_driver=None, stop_signal=None, networking_config=None, healthcheck=None, - stop_timeout=None + stop_timeout=None, runtime=None ): if version_gte(version, '1.10'): message = ('{0!r} parameter has no effect on create_container().' @@ -659,5 +664,6 @@ class ContainerConfig(dict): 'VolumeDriver': volume_driver, 'StopSignal': stop_signal, 'Healthcheck': healthcheck, - 'StopTimeout': stop_timeout + 'StopTimeout': stop_timeout, + 'Runtime': runtime }) diff --git a/tests/integration/api_container_test.py b/tests/integration/api_container_test.py index fb4c4e4a..de3fe718 100644 --- a/tests/integration/api_container_test.py +++ b/tests/integration/api_container_test.py @@ -1255,6 +1255,15 @@ class ContainerCPUTest(BaseAPIIntegrationTest): inspect_data = self.client.inspect_container(container) self.assertEqual(inspect_data['HostConfig']['CpusetCpus'], cpuset_cpus) + @requires_api_version('1.25') + def test_create_with_runtime(self): + container = self.client.create_container( + BUSYBOX, ['echo', 'test'], runtime='runc' + ) + self.tmp_containers.append(container['Id']) + config = self.client.inspect_container(container) + assert config['HostConfig']['Runtime'] == 'runc' + class LinkTest(BaseAPIIntegrationTest): def test_remove_link(self):