Add support for shm_size. Fixes #2823.

shm_size controls the size of /dev/shm in the container and requires
Docker 1.10 or newer (API version 1.22).  This requires docker-py 1.8.0
(docker/docker-py#923).

Similar to fields like `mem_limit`, `shm_size` may be specified as
either an integer or a string (e.g., `64M`).

Updating docker-py to the master branch in order to get the unreleased
dependency on `shm_size` there in place.

Signed-off-by: Spencer Rinehart <anubis@overthemonkey.com>
This commit is contained in:
Spencer Rinehart 2016-02-05 10:47:14 -06:00
parent 7b5bad6050
commit 5e6dc3521c
7 changed files with 14 additions and 2 deletions

View File

@ -72,6 +72,7 @@ DOCKER_CONFIG_KEYS = [
'read_only',
'restart',
'security_opt',
'shm_size',
'stdin_open',
'stop_signal',
'tty',

View File

@ -98,6 +98,7 @@
"read_only": {"type": "boolean"},
"restart": {"type": "string"},
"security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"shm_size": {"type": ["number", "string"]},
"stdin_open": {"type": "boolean"},
"stop_signal": {"type": "string"},
"tty": {"type": "boolean"},

View File

@ -127,6 +127,7 @@
"read_only": {"type": "boolean"},
"restart": {"type": "string"},
"security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"shm_size": {"type": ["number", "string"]},
"stdin_open": {"type": "boolean"},
"stop_signal": {"type": "string"},
"tty": {"type": "boolean"},

View File

@ -57,6 +57,7 @@ DOCKER_START_KEYS = [
'volumes_from',
'security_opt',
'cpu_quota',
'shm_size',
]
@ -654,6 +655,7 @@ class Service(object):
ipc_mode=options.get('ipc'),
cgroup_parent=options.get('cgroup_parent'),
cpu_quota=options.get('cpu_quota'),
shm_size=options.get('shm_size'),
)
def build(self, no_cache=False, pull=False, force_rm=False):

View File

@ -591,7 +591,7 @@ specifying read-only access(``ro``) or read-write(``rw``).
> - container_name
> - container_name:rw
### cpu\_shares, cpu\_quota, cpuset, domainname, hostname, ipc, mac\_address, mem\_limit, memswap\_limit, privileged, read\_only, restart, stdin\_open, tty, user, working\_dir
### cpu\_shares, cpu\_quota, cpuset, domainname, hostname, ipc, mac\_address, mem\_limit, memswap\_limit, privileged, read\_only, restart, shm\_size, stdin\_open, tty, user, working\_dir
Each of these is a single value, analogous to its
[docker run](https://docs.docker.com/engine/reference/run/) counterpart.
@ -615,6 +615,7 @@ Each of these is a single value, analogous to its
restart: always
read_only: true
shm_size: 64M
stdin_open: true
tty: true

View File

@ -1,9 +1,9 @@
PyYAML==3.11
cached-property==1.2.0
docker-py==1.7.0
dockerpty==0.4.1
docopt==0.6.1
enum34==1.0.4
git+https://github.com/docker/docker-py.git@bba8e28f822c4cd3ebe2a2ca588f41f9d7d66e26#egg=docker-py
jsonschema==2.5.1
requests==2.7.0
six==1.7.3

View File

@ -102,6 +102,12 @@ class ServiceTest(DockerClientTestCase):
container.start()
self.assertEqual(container.get('HostConfig.CpuQuota'), 40000)
def test_create_container_with_shm_size(self):
service = self.create_service('db', shm_size=67108864)
container = service.create_container()
service.start_container(container)
self.assertEqual(container.get('HostConfig.ShmSize'), 67108864)
def test_create_container_with_extra_hosts_list(self):
extra_hosts = ['somehost:162.242.195.82', 'otherhost:50.31.209.229']
service = self.create_service('db', extra_hosts=extra_hosts)