Merge pull request #1158 from chernjie/addhosts
Add extra_hosts to yml configuration --add-hosts
This commit is contained in:
commit
16f8106149
4 changed files with 111 additions and 1 deletions
|
|
@ -15,6 +15,7 @@ DOCKER_CONFIG_KEYS = [
|
|||
'entrypoint',
|
||||
'env_file',
|
||||
'environment',
|
||||
'extra_hosts',
|
||||
'hostname',
|
||||
'image',
|
||||
'links',
|
||||
|
|
@ -41,6 +42,9 @@ ALLOWED_KEYS = DOCKER_CONFIG_KEYS + [
|
|||
|
||||
DOCKER_CONFIG_HINTS = {
|
||||
'cpu_share': 'cpu_shares',
|
||||
'add_host': 'extra_hosts',
|
||||
'hosts': 'extra_hosts',
|
||||
'extra_host': 'extra_hosts',
|
||||
'link': 'links',
|
||||
'port': 'ports',
|
||||
'privilege': 'privileged',
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ DOCKER_START_KEYS = [
|
|||
'dns',
|
||||
'dns_search',
|
||||
'env_file',
|
||||
'extra_hosts',
|
||||
'net',
|
||||
'pid',
|
||||
'privileged',
|
||||
|
|
@ -448,6 +449,8 @@ class Service(object):
|
|||
|
||||
restart = parse_restart_spec(options.get('restart', None))
|
||||
|
||||
extra_hosts = build_extra_hosts(options.get('extra_hosts', None))
|
||||
|
||||
return create_host_config(
|
||||
links=self._get_links(link_to_self=one_off),
|
||||
port_bindings=port_bindings,
|
||||
|
|
@ -460,6 +463,7 @@ class Service(object):
|
|||
restart_policy=restart,
|
||||
cap_add=cap_add,
|
||||
cap_drop=cap_drop,
|
||||
extra_hosts=extra_hosts,
|
||||
pid_mode=pid
|
||||
)
|
||||
|
||||
|
|
@ -619,3 +623,28 @@ def split_port(port):
|
|||
|
||||
external_ip, external_port, internal_port = parts
|
||||
return internal_port, (external_ip, external_port or None)
|
||||
|
||||
|
||||
def build_extra_hosts(extra_hosts_config):
|
||||
if not extra_hosts_config:
|
||||
return {}
|
||||
|
||||
if isinstance(extra_hosts_config, list):
|
||||
extra_hosts_dict = {}
|
||||
for extra_hosts_line in extra_hosts_config:
|
||||
if not isinstance(extra_hosts_line, six.string_types):
|
||||
raise ConfigError(
|
||||
"extra_hosts_config \"%s\" must be either a list of strings or a string->string mapping," %
|
||||
extra_hosts_config
|
||||
)
|
||||
host, ip = extra_hosts_line.split(':')
|
||||
extra_hosts_dict.update({host.strip(): ip.strip()})
|
||||
extra_hosts_config = extra_hosts_dict
|
||||
|
||||
if isinstance(extra_hosts_config, dict):
|
||||
return extra_hosts_config
|
||||
|
||||
raise ConfigError(
|
||||
"extra_hosts_config \"%s\" must be either a list of strings or a string->string mapping," %
|
||||
extra_hosts_config
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue