diff options
| author | Joffrey F <f.joffrey@gmail.com> | 2016-02-04 14:28:09 -0800 |
|---|---|---|
| committer | Joffrey F <f.joffrey@gmail.com> | 2016-02-04 14:28:09 -0800 |
| commit | bba8e28f822c4cd3ebe2a2ca588f41f9d7d66e26 (patch) | |
| tree | 2ae96899d8d05c00e04cde015ebbe5782baf8802 | |
| parent | 084f758212c9d1839c5572da3660bb0a76c83570 (diff) | |
| parent | fca622cad7aba7871473e1e7100360f83f9efca9 (diff) | |
| download | docker-py-bba8e28f822c4cd3ebe2a2ca588f41f9d7d66e26.tar.gz | |
Merge pull request #923 from nubs/master
Add support for shm_size.
| -rw-r--r-- | docker/utils/utils.py | 9 | ||||
| -rw-r--r-- | docs/hostconfig.md | 1 | ||||
| -rw-r--r-- | tests/unit/utils_test.py | 8 |
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) |
