Skip to content

Commit 2086c20

Browse files
authored
Merge pull request #1631 from madhuri-rai07/master
Add support for ``runtime`` config
2 parents 87d5cd1 + 612c0f3 commit 2086c20

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

docker/api/container.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
238238
memswap_limit=None, cpuset=None, host_config=None,
239239
mac_address=None, labels=None, volume_driver=None,
240240
stop_signal=None, networking_config=None,
241-
healthcheck=None, stop_timeout=None):
241+
healthcheck=None, stop_timeout=None, runtime=None):
242242
"""
243243
Creates a container. Parameters are similar to those for the ``docker
244244
run`` command except it doesn't support the attach options (``-a``).
@@ -417,6 +417,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
417417
Default: 10
418418
networking_config (dict): A networking configuration generated
419419
by :py:meth:`create_networking_config`.
420+
runtime (str): Runtime to use with this container.
420421
421422
Returns:
422423
A dictionary with an image 'Id' key and a 'Warnings' key.
@@ -441,7 +442,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
441442
network_disabled, entrypoint, cpu_shares, working_dir, domainname,
442443
memswap_limit, cpuset, host_config, mac_address, labels,
443444
volume_driver, stop_signal, networking_config, healthcheck,
444-
stop_timeout
445+
stop_timeout, runtime
445446
)
446447
return self.create_container_from_config(config, name)
447448

@@ -576,6 +577,7 @@ def create_host_config(self, *args, **kwargs):
576577
values are: ``host``
577578
volumes_from (:py:class:`list`): List of container names or IDs to
578579
get volumes from.
580+
runtime (str): Runtime to use with this container.
579581
580582
581583
Returns:

docker/models/containers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ def run(self, image, command=None, stdout=True, stderr=False,
659659
volumes_from (:py:class:`list`): List of container names or IDs to
660660
get volumes from.
661661
working_dir (str): Path to the working directory.
662+
runtime (str): Runtime to use with this container.
662663
663664
Returns:
664665
The container logs, either ``STDOUT``, ``STDERR``, or both,
@@ -885,6 +886,7 @@ def prune(self, filters=None):
885886
'userns_mode',
886887
'version',
887888
'volumes_from',
889+
'runtime'
888890
]
889891

890892

docker/types/containers.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def __init__(self, version, binds=None, port_bindings=None,
120120
isolation=None, auto_remove=False, storage_opt=None,
121121
init=None, init_path=None, volume_driver=None,
122122
cpu_count=None, cpu_percent=None, nano_cpus=None,
123-
cpuset_mems=None):
123+
cpuset_mems=None, runtime=None):
124124

125125
if mem_limit is not None:
126126
self['Memory'] = parse_bytes(mem_limit)
@@ -473,6 +473,11 @@ def __init__(self, version, binds=None, port_bindings=None,
473473

474474
self['NanoCpus'] = nano_cpus
475475

476+
if runtime:
477+
if version_lt(version, '1.25'):
478+
raise host_config_version_error('runtime', '1.25')
479+
self['Runtime'] = runtime
480+
476481

477482
def host_config_type_error(param, param_value, expected):
478483
error_msg = 'Invalid type for {0} param: expected {1} but found {2}'
@@ -499,7 +504,7 @@ def __init__(
499504
working_dir=None, domainname=None, memswap_limit=None, cpuset=None,
500505
host_config=None, mac_address=None, labels=None, volume_driver=None,
501506
stop_signal=None, networking_config=None, healthcheck=None,
502-
stop_timeout=None
507+
stop_timeout=None, runtime=None
503508
):
504509
if version_gte(version, '1.10'):
505510
message = ('{0!r} parameter has no effect on create_container().'
@@ -659,5 +664,6 @@ def __init__(
659664
'VolumeDriver': volume_driver,
660665
'StopSignal': stop_signal,
661666
'Healthcheck': healthcheck,
662-
'StopTimeout': stop_timeout
667+
'StopTimeout': stop_timeout,
668+
'Runtime': runtime
663669
})

tests/integration/api_container_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,15 @@ def test_container_cpuset(self):
12551255
inspect_data = self.client.inspect_container(container)
12561256
self.assertEqual(inspect_data['HostConfig']['CpusetCpus'], cpuset_cpus)
12571257

1258+
@requires_api_version('1.25')
1259+
def test_create_with_runtime(self):
1260+
container = self.client.create_container(
1261+
BUSYBOX, ['echo', 'test'], runtime='runc'
1262+
)
1263+
self.tmp_containers.append(container['Id'])
1264+
config = self.client.inspect_container(container)
1265+
assert config['HostConfig']['Runtime'] == 'runc'
1266+
12581267

12591268
class LinkTest(BaseAPIIntegrationTest):
12601269
def test_remove_link(self):

0 commit comments

Comments
 (0)