From b1ec2f7d35ac1ba825eef2167ac7a59964ff47fe Mon Sep 17 00:00:00 2001
From: Tomas Tomecek <ttomecek@redhat.com>
Date: Fri, 22 Mar 2019 11:17:28 +0100
Subject: [PATCH] backport init and init_path to create_host_config
Resolves #1687227
Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
---
docker/utils/utils.py | 6 ++++++
docs/hostconfig.md | 2 ++
tests/unit/container_test.py | 24 ++++++++++++++++++++++++
3 files changed, 32 insertions(+)
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 2a183a0..9053889 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -610,6 +610,7 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
shm_size=None, sysctls=None, version=None, tmpfs=None,
oom_score_adj=None, dns_opt=None, cpu_shares=None,
cpuset_cpus=None, userns_mode=None, pids_limit=None,
+ init=None, init_path=None,
cpu_rt_period=None, cpu_rt_runtime=None):
host_config = {}
@@ -918,6 +919,11 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
)
host_config['CPURealtimeRuntime'] = cpu_rt_runtime
+ if init is not None:
+ host_config['Init'] = init
+ if init_path is not None:
+ host_config['InitPath'] = init_path
+
return host_config
diff --git a/docs/hostconfig.md b/docs/hostconfig.md
index c39a02c..b452a91 100644
--- a/docs/hostconfig.md
+++ b/docs/hostconfig.md
@@ -132,6 +132,8 @@ for example:
* pids_limit (int): Tune a container’s pids limit. Set -1 for unlimited.
* cpu_rt_runtime (int): Limit the CPU real-time runtime in microseconds.
* cpu_rt_period (int): Limit the CPU real-time period in microseconds.
+* init (bool): Run an init inside the container that forwards signals and reaps processes.
+* init_path (str): Path to the docker-init binary.
**Returns** (dict) HostConfig dictionary
diff --git a/tests/unit/container_test.py b/tests/unit/container_test.py
index 8c7b2c1..137e634 100644
--- a/tests/unit/container_test.py
+++ b/tests/unit/container_test.py
@@ -360,6 +360,30 @@ class CreateContainerTest(DockerClientTest):
"NetworkMode": "default"
}}'''))
+ def test_create_container_with_init(self):
+ self.client.create_container(
+ 'busybox', 'ls', host_config=self.client.create_host_config(
+ init=True, init_path="/path/to/docker-init"
+ )
+ )
+
+ args = fake_request.call_args
+ self.assertEqual(args[0][1],
+ url_prefix + 'containers/create')
+ self.assertEqual(json.loads(args[1]['data']),
+ json.loads('''
+ {"Tty": false, "Image": "busybox",
+ "Cmd": ["ls"], "AttachStdin": false,
+ "AttachStderr": true,
+ "AttachStdout": true, "OpenStdin": false,
+ "StdinOnce": false,
+ "NetworkDisabled": false,
+ "HostConfig": {
+ "Init": true,
+ "InitPath": "/path/to/docker-init",
+ "NetworkMode": "default"
+ }}'''))
+
@requires_api_version('1.18')
def test_create_container_with_host_config_cpuset(self):
self.client.create_container(
--
2.20.1