Skip to content

Commit b00dd48

Browse files
tmadshin-
authored andcommitted
Add init parameter to container HostConfig
Signed-off-by: Tomasz Madycki <[email protected]>
1 parent 9076b6c commit b00dd48

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

docker/models/containers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ def run(self, image, command=None, stdout=True, stderr=False,
491491
group_add (:py:class:`list`): List of additional group names and/or
492492
IDs that the container process will run as.
493493
hostname (str): Optional hostname for the container.
494+
init (bool): Run an init inside the container that forwards
495+
signals and reaps processes
494496
ipc_mode (str): Set the IPC mode for the container.
495497
isolation (str): Isolation technology to use. Default: `None`.
496498
labels (dict or list): A dictionary of name-value labels (e.g.
@@ -814,6 +816,7 @@ def prune(self, filters=None):
814816
'dns',
815817
'extra_hosts',
816818
'group_add',
819+
'init',
817820
'ipc_mode',
818821
'isolation',
819822
'kernel_memory',

docker/types/containers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def __init__(self, version, binds=None, port_bindings=None,
117117
oom_kill_disable=False, shm_size=None, sysctls=None,
118118
tmpfs=None, oom_score_adj=None, dns_opt=None, cpu_shares=None,
119119
cpuset_cpus=None, userns_mode=None, pids_limit=None,
120-
isolation=None, auto_remove=False, storage_opt=None):
120+
isolation=None, auto_remove=False, storage_opt=None,
121+
init=None):
121122

122123
if mem_limit is not None:
123124
self['Memory'] = parse_bytes(mem_limit)
@@ -417,6 +418,11 @@ def __init__(self, version, binds=None, port_bindings=None,
417418
raise host_config_version_error('storage_opt', '1.24')
418419
self['StorageOpt'] = storage_opt
419420

421+
if init is not None:
422+
if version_lt(version, '1.25'):
423+
raise host_config_version_error('init', '1.25')
424+
self['Init'] = init
425+
420426

421427
def host_config_type_error(param, param_value, expected):
422428
error_msg = 'Invalid type for {0} param: expected {1} but found {2}'

tests/integration/api_container_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,18 @@ def test_create_with_storage_opt(self):
439439
'size': '120G'
440440
}
441441

442+
@requires_api_version('1.25')
443+
def test_create_with_init(self):
444+
ctnr = self.client.create_container(
445+
BUSYBOX, 'true',
446+
host_config=self.client.create_host_config(
447+
init=True
448+
)
449+
)
450+
self.tmp_containers.append(ctnr['Id'])
451+
config = self.client.inspect_container(ctnr)
452+
assert config['HostConfig']['Init'] is True
453+
442454

443455
class VolumeBindTest(BaseAPIIntegrationTest):
444456
def setUp(self):

0 commit comments

Comments
 (0)