Skip to content

Commit 6ae24b9

Browse files
committed
Add support for runtime in container create and run API
1 parent dc2b24d commit 6ae24b9

File tree

5 files changed

+24
-5
lines changed

5 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): The name of the runtime tool to create 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): The name of the runtime tool to manage 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): The name of the runtime tool to create 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: 7 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,9 @@ def __init__(self, version, binds=None, port_bindings=None,
473473

474474
self['NanoCpus'] = nano_cpus
475475

476+
if runtime:
477+
self['Runtime'] = runtime
478+
476479

477480
def host_config_type_error(param, param_value, expected):
478481
error_msg = 'Invalid type for {0} param: expected {1} but found {2}'
@@ -499,7 +502,7 @@ def __init__(
499502
working_dir=None, domainname=None, memswap_limit=None, cpuset=None,
500503
host_config=None, mac_address=None, labels=None, volume_driver=None,
501504
stop_signal=None, networking_config=None, healthcheck=None,
502-
stop_timeout=None
505+
stop_timeout=None, runtime=None
503506
):
504507
if version_gte(version, '1.10'):
505508
message = ('{0!r} parameter has no effect on create_container().'
@@ -659,5 +662,6 @@ def __init__(
659662
'VolumeDriver': volume_driver,
660663
'StopSignal': stop_signal,
661664
'Healthcheck': healthcheck,
662-
'StopTimeout': stop_timeout
665+
'StopTimeout': stop_timeout,
666+
'Runtime': runtime
663667
})

docs/change-log.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ Change log
122122
* Added support for `force_update` in `TaskTemplate`
123123
* Made `name` parameter optional in `APIClient.create_volume` and
124124
`DockerClient.volumes.create`
125+
* Added support for `runtime` in `APIClient.create_container` and
126+
`DockerClient.containers.run`
125127

126128
### Bugfixes
127129

tests/integration/api_container_test.py

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

12581258

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['Config']['Runtime'] == 'runc'
1266+
1267+
12591268
class LinkTest(BaseAPIIntegrationTest):
12601269
def test_remove_link(self):
12611270
# Create containers

0 commit comments

Comments
 (0)