Add sysctl option support when creating service

Closes #3765

Signed-off-by: Jari Takkala <jtakkala@gmail.com>
This commit is contained in:
Jari Takkala 2016-07-29 06:46:42 -04:00
parent 0e28163ccb
commit 91620ae97b
3 changed files with 14 additions and 5 deletions

View File

@ -83,6 +83,7 @@ DOCKER_CONFIG_KEYS = [
'shm_size',
'stdin_open',
'stop_signal',
'sysctls',
'tty',
'user',
'volume_driver',
@ -629,6 +630,9 @@ def process_service(service_config):
if 'extra_hosts' in service_dict:
service_dict['extra_hosts'] = parse_extra_hosts(service_dict['extra_hosts'])
if 'sysctls' in service_dict:
service_dict['sysctls'] = build_string_dict(parse_sysctls(service_dict['sysctls']))
for field in ['dns', 'dns_search', 'tmpfs']:
if field in service_dict:
service_dict[field] = to_list(service_dict[field])
@ -757,6 +761,7 @@ def merge_service_dicts(base, override, version):
md.merge_mapping('labels', parse_labels)
md.merge_mapping('ulimits', parse_ulimits)
md.merge_mapping('networks', parse_networks)
md.merge_mapping('sysctls', parse_sysctls)
md.merge_sequence('links', ServiceLink.parse)
for field in ['volumes', 'devices']:
@ -831,11 +836,11 @@ def merge_environment(base, override):
return env
def split_label(label):
if '=' in label:
return label.split('=', 1)
def split_kv(kvpair):
if '=' in kvpair:
return kvpair.split('=', 1)
else:
return label, ''
return kvpair, ''
def parse_dict_or_list(split_func, type_name, arguments):
@ -856,8 +861,9 @@ def parse_dict_or_list(split_func, type_name, arguments):
parse_build_arguments = functools.partial(parse_dict_or_list, split_env, 'build arguments')
parse_environment = functools.partial(parse_dict_or_list, split_env, 'environment')
parse_labels = functools.partial(parse_dict_or_list, split_label, 'labels')
parse_labels = functools.partial(parse_dict_or_list, split_kv, 'labels')
parse_networks = functools.partial(parse_dict_or_list, lambda k: (k, None), 'networks')
parse_sysctls = functools.partial(parse_dict_or_list, split_kv, 'sysctls')
def parse_ulimits(ulimits):

View File

@ -193,6 +193,7 @@
"restart": {"type": "string"},
"security_opt": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"shm_size": {"type": ["number", "string"]},
"sysctls": {"$ref": "#/definitions/list_or_dict"},
"stdin_open": {"type": "boolean"},
"stop_signal": {"type": "string"},
"tmpfs": {"$ref": "#/definitions/string_or_list"},

View File

@ -62,6 +62,7 @@ DOCKER_START_KEYS = [
'restart',
'security_opt',
'shm_size',
'sysctls',
'volumes_from',
]
@ -707,6 +708,7 @@ class Service(object):
cgroup_parent=options.get('cgroup_parent'),
cpu_quota=options.get('cpu_quota'),
shm_size=options.get('shm_size'),
sysctls=options.get('sysctls'),
tmpfs=options.get('tmpfs'),
oom_score_adj=options.get('oom_score_adj'),
mem_swappiness=options.get('mem_swappiness'),