From 6ae24b9e60cd8f080a6c657ccbdffd22056169dd Mon Sep 17 00:00:00 2001 From: Madhuri Kumari Date: Thu, 1 Jun 2017 15:09:46 +0000 Subject: [PATCH] Add support for ``runtime`` in container create and run API --- docker/api/container.py | 6 ++++-- docker/models/containers.py | 2 ++ docker/types/containers.py | 10 +++++++--- docs/change-log.md | 2 ++ tests/integration/api_container_test.py | 9 +++++++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/docker/api/container.py b/docker/api/container.py index 97b54059..0abfca4f 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): The name of the runtime tool to create 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): The name of the runtime tool to manage container. Returns: diff --git a/docker/models/containers.py b/docker/models/containers.py index 4bb2cf86..46f900e0 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): The name of the runtime tool to create 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..f834c785 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,9 @@ class HostConfig(dict): self['NanoCpus'] = nano_cpus + if runtime: + 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 +502,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 +662,6 @@ class ContainerConfig(dict): 'VolumeDriver': volume_driver, 'StopSignal': stop_signal, 'Healthcheck': healthcheck, - 'StopTimeout': stop_timeout + 'StopTimeout': stop_timeout, + 'Runtime': runtime }) diff --git a/docs/change-log.md b/docs/change-log.md index 3d58f931..20bf9e09 100644 --- a/docs/change-log.md +++ b/docs/change-log.md @@ -122,6 +122,8 @@ Change log * Added support for `force_update` in `TaskTemplate` * Made `name` parameter optional in `APIClient.create_volume` and `DockerClient.volumes.create` +* Added support for `runtime` in `APIClient.create_container` and + `DockerClient.containers.run` ### Bugfixes diff --git a/tests/integration/api_container_test.py b/tests/integration/api_container_test.py index fb4c4e4a..c499e35e 100644 --- a/tests/integration/api_container_test.py +++ b/tests/integration/api_container_test.py @@ -1256,6 +1256,15 @@ class ContainerCPUTest(BaseAPIIntegrationTest): self.assertEqual(inspect_data['HostConfig']['CpusetCpus'], cpuset_cpus) + 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['Config']['Runtime'] == 'runc' + + class LinkTest(BaseAPIIntegrationTest): def test_remove_link(self): # Create containers