summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <f.joffrey@gmail.com>2016-08-01 17:32:18 -0700
committerGitHub <noreply@github.com>2016-08-01 17:32:18 -0700
commit650cc70e934044fcb5dfd27fd27777f91c337b6c (patch)
tree2a7dda0fcf825f8a03efefa58332c37dff61bcdf
parentf99dc45d827b0ab3c4fb6faeb46e99d58977c572 (diff)
parentdec29e1c10be3fbba239891e3bf47dc6b40ee567 (diff)
downloaddocker-py-650cc70e934044fcb5dfd27fd27777f91c337b6c.tar.gz
Merge pull request #1145 from jtakkala/1144-sysctl-support
Add support for sysctl when creating container
-rw-r--r--docker/utils/utils.py9
-rw-r--r--docs/hostconfig.md1
-rw-r--r--tests/unit/container_test.py27
3 files changed, 36 insertions, 1 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 1cfc8ac..00a7af1 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -619,7 +619,7 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
blkio_weight_device=None, device_read_bps=None,
device_write_bps=None, device_read_iops=None,
device_write_iops=None, oom_kill_disable=False,
- shm_size=None, version=None, tmpfs=None,
+ shm_size=None, sysctls=None, version=None, tmpfs=None,
oom_score_adj=None):
host_config = {}
@@ -725,6 +725,13 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
host_config['SecurityOpt'] = security_opt
+ if sysctls:
+ if not isinstance(sysctls, dict):
+ raise host_config_type_error('sysctls', sysctls, 'dict')
+ host_config['Sysctls'] = {}
+ for k, v in six.iteritems(sysctls):
+ host_config['Sysctls'][k] = six.text_type(v)
+
if volumes_from is not None:
if isinstance(volumes_from, six.string_types):
volumes_from = volumes_from.split(',')
diff --git a/docs/hostconfig.md b/docs/hostconfig.md
index c1e2353..01c4625 100644
--- a/docs/hostconfig.md
+++ b/docs/hostconfig.md
@@ -123,6 +123,7 @@ for example:
for more information.
* tmpfs: Temporary filesystems to mouunt. See [Using tmpfs](tmpfs.md) for more
information.
+* sysctls (dict): Kernel parameters to set in the container.
**Returns** (dict) HostConfig dictionary
diff --git a/tests/unit/container_test.py b/tests/unit/container_test.py
index 2a72c17..4c94c84 100644
--- a/tests/unit/container_test.py
+++ b/tests/unit/container_test.py
@@ -1074,6 +1074,33 @@ class CreateContainerTest(DockerClientTest):
DEFAULT_TIMEOUT_SECONDS
)
+ @requires_api_version('1.24')
+ def test_create_container_with_sysctl(self):
+ self.client.create_container(
+ 'busybox', 'true',
+ host_config=self.client.create_host_config(
+ sysctls={
+ 'net.core.somaxconn': 1024,
+ 'net.ipv4.tcp_syncookies': '0',
+ }
+ )
+ )
+
+ args = fake_request.call_args
+ self.assertEqual(args[0][1], url_prefix + 'containers/create')
+ expected_payload = self.base_create_payload()
+ expected_payload['HostConfig'] = self.client.create_host_config()
+ expected_payload['HostConfig']['Sysctls'] = {
+ 'net.core.somaxconn': '1024', 'net.ipv4.tcp_syncookies': '0',
+ }
+ self.assertEqual(json.loads(args[1]['data']), expected_payload)
+ self.assertEqual(
+ args[1]['headers'], {'Content-Type': 'application/json'}
+ )
+ self.assertEqual(
+ args[1]['timeout'], DEFAULT_TIMEOUT_SECONDS
+ )
+
class ContainerTest(DockerClientTest):
def test_list_containers(self):