summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer Rinehart <anubis@overthemonkey.com>2016-02-04 10:41:55 -0600
committerSpencer Rinehart <anubis@overthemonkey.com>2016-02-04 12:33:05 -0600
commitfca622cad7aba7871473e1e7100360f83f9efca9 (patch)
treef2dc06005cc589a91661172de5ac2d5f87105167
parent60d814d742067f3e349119809935f8c0cb6c3b3b (diff)
downloaddocker-py-fca622cad7aba7871473e1e7100360f83f9efca9.tar.gz
Add support for shm_size.
--shm-size was added to Docker in 1.10 via docker/docker#16168. See docker/compose#2823 for more details. Signed-off-by: Spencer Rinehart <anubis@overthemonkey.com>
-rw-r--r--docker/utils/utils.py9
-rw-r--r--docs/hostconfig.md1
-rw-r--r--tests/unit/utils_test.py8
3 files changed, 17 insertions, 1 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index 07d57d1..549fa6b 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -556,7 +556,8 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
security_opt=None, ulimits=None, log_config=None,
mem_limit=None, memswap_limit=None, mem_swappiness=None,
cgroup_parent=None, group_add=None, cpu_quota=None,
- cpu_period=None, oom_kill_disable=False, version=None):
+ cpu_period=None, oom_kill_disable=False, shm_size=None,
+ version=None):
host_config = {}
@@ -589,6 +590,12 @@ def create_host_config(binds=None, port_bindings=None, lxc_conf=None,
host_config['MemorySwappiness'] = mem_swappiness
+ if shm_size is not None:
+ if isinstance(shm_size, six.string_types):
+ shm_size = parse_bytes(shm_size)
+
+ host_config['ShmSize'] = shm_size
+
if pid_mode not in (None, 'host'):
raise host_config_value_error('pid_mode', pid_mode)
elif pid_mode:
diff --git a/docs/hostconfig.md b/docs/hostconfig.md
index b7b3b66..4b841d5 100644
--- a/docs/hostconfig.md
+++ b/docs/hostconfig.md
@@ -103,6 +103,7 @@ for example:
allowed to consume.
* mem_swappiness (int): Tune a container's memory swappiness behavior.
Accepts number between 0 and 100.
+* shm_size (str or int): Size of /dev/shm. (e.g. `'1G'`)
* cpu_group (int): The length of a CPU period in microseconds.
* cpu_period (int): Microseconds of CPU time that the container can get in a
CPU period.
diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py
index 63ea10e..f1b5523 100644
--- a/tests/unit/utils_test.py
+++ b/tests/unit/utils_test.py
@@ -64,6 +64,14 @@ class HostConfigTest(base.BaseTestCase):
config = create_host_config(version='1.20', cpu_period=1999)
self.assertEqual(config.get('CpuPeriod'), 1999)
+ def test_create_host_config_with_shm_size(self):
+ config = create_host_config(version='1.22', shm_size=67108864)
+ self.assertEqual(config.get('ShmSize'), 67108864)
+
+ def test_create_host_config_with_shm_size_in_mb(self):
+ config = create_host_config(version='1.22', shm_size='64M')
+ self.assertEqual(config.get('ShmSize'), 67108864)
+
def test_create_host_config_with_oom_kill_disable(self):
config = create_host_config(version='1.20', oom_kill_disable=True)
self.assertEqual(config.get('OomKillDisable'), True)