From 13b5f785a7ab459960aae82fae00e4245e391387 Mon Sep 17 00:00:00 2001 From: Tomasz Madycki Date: Thu, 16 Feb 2017 01:26:03 +0100 Subject: [PATCH] Add init parameter to container HostConfig Signed-off-by: Tomasz Madycki --- docker/models/containers.py | 3 +++ docker/types/containers.py | 8 +++++++- tests/integration/api_container_test.py | 12 ++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docker/models/containers.py b/docker/models/containers.py index 2b8481c0..f297a5d2 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -491,6 +491,8 @@ class ContainerCollection(Collection): group_add (:py:class:`list`): List of additional group names and/or IDs that the container process will run as. hostname (str): Optional hostname for the container. + init (bool): Run an init inside the container that forwards + signals and reaps processes ipc_mode (str): Set the IPC mode for the container. isolation (str): Isolation technology to use. Default: `None`. labels (dict or list): A dictionary of name-value labels (e.g. @@ -814,6 +816,7 @@ RUN_HOST_CONFIG_KWARGS = [ 'dns', 'extra_hosts', 'group_add', + 'init', 'ipc_mode', 'isolation', 'kernel_memory', diff --git a/docker/types/containers.py b/docker/types/containers.py index 9a8d1574..8e8a87d6 100644 --- a/docker/types/containers.py +++ b/docker/types/containers.py @@ -117,7 +117,8 @@ class HostConfig(dict): oom_kill_disable=False, shm_size=None, sysctls=None, tmpfs=None, oom_score_adj=None, dns_opt=None, cpu_shares=None, cpuset_cpus=None, userns_mode=None, pids_limit=None, - isolation=None, auto_remove=False, storage_opt=None): + isolation=None, auto_remove=False, storage_opt=None, + init=None): if mem_limit is not None: self['Memory'] = parse_bytes(mem_limit) @@ -417,6 +418,11 @@ class HostConfig(dict): raise host_config_version_error('storage_opt', '1.24') self['StorageOpt'] = storage_opt + if init is not None: + if version_lt(version, '1.25'): + raise host_config_version_error('init', '1.25') + self['Init'] = init + def host_config_type_error(param, param_value, expected): error_msg = 'Invalid type for {0} param: expected {1} but found {2}' diff --git a/tests/integration/api_container_test.py b/tests/integration/api_container_test.py index e261ef3d..a98e8b11 100644 --- a/tests/integration/api_container_test.py +++ b/tests/integration/api_container_test.py @@ -439,6 +439,18 @@ class CreateContainerTest(BaseAPIIntegrationTest): 'size': '120G' } + @requires_api_version('1.25') + def test_create_with_init(self): + ctnr = self.client.create_container( + BUSYBOX, 'true', + host_config=self.client.create_host_config( + init=True + ) + ) + self.tmp_containers.append(ctnr['Id']) + config = self.client.inspect_container(ctnr) + assert config['HostConfig']['Init'] is True + class VolumeBindTest(BaseAPIIntegrationTest): def setUp(self):