Skip to content

Commit 8ea6ecc

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

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

docker/models/containers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ def run(self, image, command=None, stdout=True, stderr=False,
493493
hostname (str): Optional hostname for the container.
494494
init (bool): Run an init inside the container that forwards
495495
signals and reaps processes
496+
init_path (bool): Path to the docker-init binary
496497
ipc_mode (str): Set the IPC mode for the container.
497498
isolation (str): Isolation technology to use. Default: `None`.
498499
labels (dict or list): A dictionary of name-value labels (e.g.
@@ -817,6 +818,7 @@ def prune(self, filters=None):
817818
'extra_hosts',
818819
'group_add',
819820
'init',
821+
'init_path',
820822
'ipc_mode',
821823
'isolation',
822824
'kernel_memory',

docker/types/containers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def __init__(self, version, binds=None, port_bindings=None,
118118
tmpfs=None, oom_score_adj=None, dns_opt=None, cpu_shares=None,
119119
cpuset_cpus=None, userns_mode=None, pids_limit=None,
120120
isolation=None, auto_remove=False, storage_opt=None,
121-
init=None):
121+
init=None, init_path=None):
122122

123123
if mem_limit is not None:
124124
self['Memory'] = parse_bytes(mem_limit)
@@ -423,6 +423,11 @@ def __init__(self, version, binds=None, port_bindings=None,
423423
raise host_config_version_error('init', '1.25')
424424
self['Init'] = init
425425

426+
if init_path:
427+
if version_lt(version, '1.25'):
428+
raise host_config_version_error('init', '1.25')
429+
self['InitPath'] = init_path
430+
426431

427432
def host_config_type_error(param, param_value, expected):
428433
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
@@ -451,6 +451,18 @@ def test_create_with_init(self):
451451
config = self.client.inspect_container(ctnr)
452452
assert config['HostConfig']['Init'] is True
453453

454+
@requires_api_version('1.25')
455+
def test_create_with_init_path(self):
456+
ctnr = self.client.create_container(
457+
BUSYBOX, 'true',
458+
host_config=self.client.create_host_config(
459+
init_path="/usr/libexec/docker-init"
460+
)
461+
)
462+
self.tmp_containers.append(ctnr['Id'])
463+
config = self.client.inspect_container(ctnr)
464+
assert config['HostConfig']['InitPath'] == "/usr/libexec/docker-init"
465+
454466

455467
class VolumeBindTest(BaseAPIIntegrationTest):
456468
def setUp(self):

0 commit comments

Comments
 (0)