1
0

service.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. from __future__ import unicode_literals
  2. from __future__ import absolute_import
  3. from collections import namedtuple
  4. import logging
  5. import re
  6. import sys
  7. from operator import attrgetter
  8. import six
  9. from docker.errors import APIError
  10. from docker.utils import create_host_config, LogConfig
  11. from . import __version__
  12. from .config import DOCKER_CONFIG_KEYS, merge_environment
  13. from .const import (
  14. LABEL_CONTAINER_NUMBER,
  15. LABEL_ONE_OFF,
  16. LABEL_PROJECT,
  17. LABEL_SERVICE,
  18. LABEL_VERSION,
  19. )
  20. from .container import Container, get_container_name
  21. from .progress_stream import stream_output, StreamOutputError
  22. log = logging.getLogger(__name__)
  23. DOCKER_START_KEYS = [
  24. 'cap_add',
  25. 'cap_drop',
  26. 'devices',
  27. 'dns',
  28. 'dns_search',
  29. 'env_file',
  30. 'extra_hosts',
  31. 'read_only',
  32. 'net',
  33. 'log_driver',
  34. 'pid',
  35. 'privileged',
  36. 'restart',
  37. 'volumes_from',
  38. ]
  39. VALID_NAME_CHARS = '[a-zA-Z0-9]'
  40. class BuildError(Exception):
  41. def __init__(self, service, reason):
  42. self.service = service
  43. self.reason = reason
  44. class CannotBeScaledError(Exception):
  45. pass
  46. class ConfigError(ValueError):
  47. pass
  48. VolumeSpec = namedtuple('VolumeSpec', 'external internal mode')
  49. ServiceName = namedtuple('ServiceName', 'project service number')
  50. class Service(object):
  51. def __init__(self, name, client=None, project='default', links=None, external_links=None, volumes_from=None, net=None, **options):
  52. if not re.match('^%s+$' % VALID_NAME_CHARS, name):
  53. raise ConfigError('Invalid service name "%s" - only %s are allowed' % (name, VALID_NAME_CHARS))
  54. if not re.match('^%s+$' % VALID_NAME_CHARS, project):
  55. raise ConfigError('Invalid project name "%s" - only %s are allowed' % (project, VALID_NAME_CHARS))
  56. if 'image' in options and 'build' in options:
  57. raise ConfigError('Service %s has both an image and build path specified. A service can either be built to image or use an existing image, not both.' % name)
  58. if 'image' not in options and 'build' not in options:
  59. raise ConfigError('Service %s has neither an image nor a build path specified. Exactly one must be provided.' % name)
  60. self.name = name
  61. self.client = client
  62. self.project = project
  63. self.links = links or []
  64. self.external_links = external_links or []
  65. self.volumes_from = volumes_from or []
  66. self.net = net or None
  67. self.options = options
  68. def containers(self, stopped=False, one_off=False):
  69. containers = [
  70. Container.from_ps(self.client, container)
  71. for container in self.client.containers(
  72. all=stopped,
  73. filters={'label': self.labels(one_off=one_off)})]
  74. if not containers:
  75. check_for_legacy_containers(
  76. self.client,
  77. self.project,
  78. [self.name],
  79. stopped=stopped,
  80. one_off=one_off)
  81. return containers
  82. def get_container(self, number=1):
  83. """Return a :class:`compose.container.Container` for this service. The
  84. container must be active, and match `number`.
  85. """
  86. labels = self.labels() + ['{0}={1}'.format(LABEL_CONTAINER_NUMBER, number)]
  87. for container in self.client.containers(filters={'label': labels}):
  88. return Container.from_ps(self.client, container)
  89. raise ValueError("No container found for %s_%s" % (self.name, number))
  90. def start(self, **options):
  91. for c in self.containers(stopped=True):
  92. self.start_container_if_stopped(c, **options)
  93. def stop(self, **options):
  94. for c in self.containers():
  95. log.info("Stopping %s..." % c.name)
  96. c.stop(**options)
  97. def kill(self, **options):
  98. for c in self.containers():
  99. log.info("Killing %s..." % c.name)
  100. c.kill(**options)
  101. def restart(self, **options):
  102. for c in self.containers():
  103. log.info("Restarting %s..." % c.name)
  104. c.restart(**options)
  105. def scale(self, desired_num):
  106. """
  107. Adjusts the number of containers to the specified number and ensures
  108. they are running.
  109. - creates containers until there are at least `desired_num`
  110. - stops containers until there are at most `desired_num` running
  111. - starts containers until there are at least `desired_num` running
  112. - removes all stopped containers
  113. """
  114. if not self.can_be_scaled():
  115. raise CannotBeScaledError()
  116. # Create enough containers
  117. containers = self.containers(stopped=True)
  118. while len(containers) < desired_num:
  119. containers.append(self.create_container(detach=True))
  120. running_containers = []
  121. stopped_containers = []
  122. for c in containers:
  123. if c.is_running:
  124. running_containers.append(c)
  125. else:
  126. stopped_containers.append(c)
  127. running_containers.sort(key=lambda c: c.number)
  128. stopped_containers.sort(key=lambda c: c.number)
  129. # Stop containers
  130. while len(running_containers) > desired_num:
  131. c = running_containers.pop()
  132. log.info("Stopping %s..." % c.name)
  133. c.stop(timeout=1)
  134. stopped_containers.append(c)
  135. # Start containers
  136. while len(running_containers) < desired_num:
  137. c = stopped_containers.pop(0)
  138. log.info("Starting %s..." % c.name)
  139. self.start_container(c)
  140. running_containers.append(c)
  141. self.remove_stopped()
  142. def remove_stopped(self, **options):
  143. for c in self.containers(stopped=True):
  144. if not c.is_running:
  145. log.info("Removing %s..." % c.name)
  146. c.remove(**options)
  147. def create_container(self,
  148. one_off=False,
  149. insecure_registry=False,
  150. do_build=True,
  151. previous_container=None,
  152. number=None,
  153. **override_options):
  154. """
  155. Create a container for this service. If the image doesn't exist, attempt to pull
  156. it.
  157. """
  158. container_options = self._get_container_create_options(
  159. override_options,
  160. number or self._next_container_number(one_off=one_off),
  161. one_off=one_off,
  162. previous_container=previous_container,
  163. )
  164. if (do_build and
  165. self.can_be_built() and
  166. not self.client.images(name=self.full_name)):
  167. self.build()
  168. try:
  169. return Container.create(self.client, **container_options)
  170. except APIError as e:
  171. if e.response.status_code == 404 and e.explanation and 'No such image' in str(e.explanation):
  172. self.pull(insecure_registry=insecure_registry)
  173. return Container.create(self.client, **container_options)
  174. raise
  175. def recreate_containers(self, insecure_registry=False, do_build=True, **override_options):
  176. """
  177. If a container for this service doesn't exist, create and start one. If there are
  178. any, stop them, create+start new ones, and remove the old containers.
  179. """
  180. containers = self.containers(stopped=True)
  181. if not containers:
  182. container = self.create_container(
  183. insecure_registry=insecure_registry,
  184. do_build=do_build,
  185. **override_options)
  186. self.start_container(container)
  187. return [container]
  188. return [
  189. self.recreate_container(
  190. c,
  191. insecure_registry=insecure_registry,
  192. **override_options)
  193. for c in containers
  194. ]
  195. def recreate_container(self, container, **override_options):
  196. """Recreate a container.
  197. The original container is renamed to a temporary name so that data
  198. volumes can be copied to the new container, before the original
  199. container is removed.
  200. """
  201. log.info("Recreating %s..." % container.name)
  202. try:
  203. container.stop()
  204. except APIError as e:
  205. if (e.response.status_code == 500
  206. and e.explanation
  207. and 'no such process' in str(e.explanation)):
  208. pass
  209. else:
  210. raise
  211. # Use a hopefully unique container name by prepending the short id
  212. self.client.rename(
  213. container.id,
  214. '%s_%s' % (container.short_id, container.name))
  215. override_options = dict(
  216. override_options,
  217. environment=merge_environment(
  218. override_options.get('environment'),
  219. {'affinity:container': '=' + container.id}))
  220. new_container = self.create_container(
  221. do_build=False,
  222. previous_container=container,
  223. number=container.labels.get(LABEL_CONTAINER_NUMBER),
  224. **override_options)
  225. self.start_container(new_container)
  226. container.remove()
  227. return new_container
  228. def start_container_if_stopped(self, container):
  229. if container.is_running:
  230. return container
  231. else:
  232. log.info("Starting %s..." % container.name)
  233. return self.start_container(container)
  234. def start_container(self, container):
  235. container.start()
  236. return container
  237. def start_or_create_containers(
  238. self,
  239. insecure_registry=False,
  240. detach=False,
  241. do_build=True):
  242. containers = self.containers(stopped=True)
  243. if not containers:
  244. new_container = self.create_container(
  245. insecure_registry=insecure_registry,
  246. detach=detach,
  247. do_build=do_build,
  248. )
  249. return [self.start_container(new_container)]
  250. else:
  251. return [self.start_container_if_stopped(c) for c in containers]
  252. def get_linked_names(self):
  253. return [s.name for (s, _) in self.links]
  254. def get_volumes_from_names(self):
  255. return [s.name for s in self.volumes_from if isinstance(s, Service)]
  256. def get_net_name(self):
  257. if isinstance(self.net, Service):
  258. return self.net.name
  259. else:
  260. return
  261. def get_container_name(self, number, one_off=False):
  262. # TODO: Implement issue #652 here
  263. return build_container_name(self.project, self.name, number, one_off)
  264. # TODO: this would benefit from github.com/docker/docker/pull/11943
  265. # to remove the need to inspect every container
  266. def _next_container_number(self, one_off=False):
  267. numbers = [
  268. Container.from_ps(self.client, container).number
  269. for container in self.client.containers(
  270. all=True,
  271. filters={'label': self.labels(one_off=one_off)})
  272. ]
  273. return 1 if not numbers else max(numbers) + 1
  274. def _get_links(self, link_to_self):
  275. links = []
  276. for service, link_name in self.links:
  277. for container in service.containers():
  278. links.append((container.name, link_name or service.name))
  279. links.append((container.name, container.name))
  280. links.append((container.name, container.name_without_project))
  281. if link_to_self:
  282. for container in self.containers():
  283. links.append((container.name, self.name))
  284. links.append((container.name, container.name))
  285. links.append((container.name, container.name_without_project))
  286. for external_link in self.external_links:
  287. if ':' not in external_link:
  288. link_name = external_link
  289. else:
  290. external_link, link_name = external_link.split(':')
  291. links.append((external_link, link_name))
  292. return links
  293. def _get_volumes_from(self):
  294. volumes_from = []
  295. for volume_source in self.volumes_from:
  296. if isinstance(volume_source, Service):
  297. containers = volume_source.containers(stopped=True)
  298. if not containers:
  299. volumes_from.append(volume_source.create_container().id)
  300. else:
  301. volumes_from.extend(map(attrgetter('id'), containers))
  302. elif isinstance(volume_source, Container):
  303. volumes_from.append(volume_source.id)
  304. return volumes_from
  305. def _get_net(self):
  306. if not self.net:
  307. return "bridge"
  308. if isinstance(self.net, Service):
  309. containers = self.net.containers()
  310. if len(containers) > 0:
  311. net = 'container:' + containers[0].id
  312. else:
  313. log.warning("Warning: Service %s is trying to use reuse the network stack "
  314. "of another service that is not running." % (self.net.name))
  315. net = None
  316. elif isinstance(self.net, Container):
  317. net = 'container:' + self.net.id
  318. else:
  319. net = self.net
  320. return net
  321. def _get_container_create_options(
  322. self,
  323. override_options,
  324. number,
  325. one_off=False,
  326. previous_container=None):
  327. container_options = dict(
  328. (k, self.options[k])
  329. for k in DOCKER_CONFIG_KEYS if k in self.options)
  330. container_options.update(override_options)
  331. container_options['name'] = self.get_container_name(number, one_off)
  332. # If a qualified hostname was given, split it into an
  333. # unqualified hostname and a domainname unless domainname
  334. # was also given explicitly. This matches the behavior of
  335. # the official Docker CLI in that scenario.
  336. if ('hostname' in container_options
  337. and 'domainname' not in container_options
  338. and '.' in container_options['hostname']):
  339. parts = container_options['hostname'].partition('.')
  340. container_options['hostname'] = parts[0]
  341. container_options['domainname'] = parts[2]
  342. if 'ports' in container_options or 'expose' in self.options:
  343. ports = []
  344. all_ports = container_options.get('ports', []) + self.options.get('expose', [])
  345. for port in all_ports:
  346. port = str(port)
  347. if ':' in port:
  348. port = port.split(':')[-1]
  349. if '/' in port:
  350. port = tuple(port.split('/'))
  351. ports.append(port)
  352. container_options['ports'] = ports
  353. override_options['binds'] = merge_volume_bindings(
  354. container_options.get('volumes') or [],
  355. previous_container)
  356. if 'volumes' in container_options:
  357. container_options['volumes'] = dict(
  358. (parse_volume_spec(v).internal, {})
  359. for v in container_options['volumes'])
  360. container_options['environment'] = merge_environment(
  361. self.options.get('environment'),
  362. override_options.get('environment'))
  363. if self.can_be_built():
  364. container_options['image'] = self.full_name
  365. container_options['labels'] = build_container_labels(
  366. container_options.get('labels', {}),
  367. self.labels(one_off=one_off),
  368. number)
  369. # Delete options which are only used when starting
  370. for key in DOCKER_START_KEYS:
  371. container_options.pop(key, None)
  372. container_options['host_config'] = self._get_container_host_config(
  373. override_options,
  374. one_off=one_off)
  375. return container_options
  376. def _get_container_host_config(self, override_options, one_off=False):
  377. options = dict(self.options, **override_options)
  378. port_bindings = build_port_bindings(options.get('ports') or [])
  379. privileged = options.get('privileged', False)
  380. cap_add = options.get('cap_add', None)
  381. cap_drop = options.get('cap_drop', None)
  382. log_config = LogConfig(type=options.get('log_driver', 'json-file'))
  383. pid = options.get('pid', None)
  384. dns = options.get('dns', None)
  385. if isinstance(dns, six.string_types):
  386. dns = [dns]
  387. dns_search = options.get('dns_search', None)
  388. if isinstance(dns_search, six.string_types):
  389. dns_search = [dns_search]
  390. restart = parse_restart_spec(options.get('restart', None))
  391. extra_hosts = build_extra_hosts(options.get('extra_hosts', None))
  392. read_only = options.get('read_only', None)
  393. devices = options.get('devices', None)
  394. return create_host_config(
  395. links=self._get_links(link_to_self=one_off),
  396. port_bindings=port_bindings,
  397. binds=options.get('binds'),
  398. volumes_from=self._get_volumes_from(),
  399. privileged=privileged,
  400. network_mode=self._get_net(),
  401. devices=devices,
  402. dns=dns,
  403. dns_search=dns_search,
  404. restart_policy=restart,
  405. cap_add=cap_add,
  406. cap_drop=cap_drop,
  407. log_config=log_config,
  408. extra_hosts=extra_hosts,
  409. read_only=read_only,
  410. pid_mode=pid
  411. )
  412. def build(self, no_cache=False):
  413. log.info('Building %s...' % self.name)
  414. path = six.binary_type(self.options['build'])
  415. build_output = self.client.build(
  416. path=path,
  417. tag=self.full_name,
  418. stream=True,
  419. rm=True,
  420. nocache=no_cache,
  421. dockerfile=self.options.get('dockerfile', None),
  422. )
  423. try:
  424. all_events = stream_output(build_output, sys.stdout)
  425. except StreamOutputError as e:
  426. raise BuildError(self, unicode(e))
  427. # Ensure the HTTP connection is not reused for another
  428. # streaming command, as the Docker daemon can sometimes
  429. # complain about it
  430. self.client.close()
  431. image_id = None
  432. for event in all_events:
  433. if 'stream' in event:
  434. match = re.search(r'Successfully built ([0-9a-f]+)', event.get('stream', ''))
  435. if match:
  436. image_id = match.group(1)
  437. if image_id is None:
  438. raise BuildError(self, event if all_events else 'Unknown')
  439. return image_id
  440. def can_be_built(self):
  441. return 'build' in self.options
  442. @property
  443. def full_name(self):
  444. """
  445. The tag to give to images built for this service.
  446. """
  447. return '%s_%s' % (self.project, self.name)
  448. def labels(self, one_off=False):
  449. return [
  450. '{0}={1}'.format(LABEL_PROJECT, self.project),
  451. '{0}={1}'.format(LABEL_SERVICE, self.name),
  452. '{0}={1}'.format(LABEL_ONE_OFF, "True" if one_off else "False")
  453. ]
  454. def can_be_scaled(self):
  455. for port in self.options.get('ports', []):
  456. if ':' in str(port):
  457. return False
  458. return True
  459. def pull(self, insecure_registry=False):
  460. if 'image' not in self.options:
  461. return
  462. repo, tag = parse_repository_tag(self.options['image'])
  463. tag = tag or 'latest'
  464. log.info('Pulling %s (%s:%s)...' % (self.name, repo, tag))
  465. output = self.client.pull(
  466. repo,
  467. tag=tag,
  468. stream=True,
  469. insecure_registry=insecure_registry)
  470. stream_output(output, sys.stdout)
  471. def get_container_data_volumes(container, volumes_option):
  472. """Find the container data volumes that are in `volumes_option`, and return
  473. a mapping of volume bindings for those volumes.
  474. """
  475. volumes = []
  476. volumes_option = volumes_option or []
  477. container_volumes = container.get('Volumes') or {}
  478. image_volumes = container.image_config['ContainerConfig'].get('Volumes') or {}
  479. for volume in set(volumes_option + image_volumes.keys()):
  480. volume = parse_volume_spec(volume)
  481. # No need to preserve host volumes
  482. if volume.external:
  483. continue
  484. volume_path = container_volumes.get(volume.internal)
  485. # New volume, doesn't exist in the old container
  486. if not volume_path:
  487. continue
  488. # Copy existing volume from old container
  489. volume = volume._replace(external=volume_path)
  490. volumes.append(build_volume_binding(volume))
  491. return dict(volumes)
  492. def merge_volume_bindings(volumes_option, previous_container):
  493. """Return a list of volume bindings for a container. Container data volumes
  494. are replaced by those from the previous container.
  495. """
  496. volume_bindings = dict(
  497. build_volume_binding(parse_volume_spec(volume))
  498. for volume in volumes_option or []
  499. if ':' in volume)
  500. if previous_container:
  501. volume_bindings.update(
  502. get_container_data_volumes(previous_container, volumes_option))
  503. return volume_bindings
  504. def build_container_name(project, service, number, one_off=False):
  505. bits = [project, service]
  506. if one_off:
  507. bits.append('run')
  508. return '_'.join(bits + [str(number)])
  509. def build_container_labels(label_options, service_labels, number, one_off=False):
  510. labels = label_options or {}
  511. labels.update(label.split('=', 1) for label in service_labels)
  512. labels[LABEL_CONTAINER_NUMBER] = str(number)
  513. labels[LABEL_VERSION] = __version__
  514. return labels
  515. def check_for_legacy_containers(
  516. client,
  517. project,
  518. services,
  519. stopped=False,
  520. one_off=False):
  521. """Check if there are containers named using the old naming convention
  522. and warn the user that those containers may need to be migrated to
  523. using labels, so that compose can find them.
  524. """
  525. for container in client.containers(all=stopped):
  526. name = get_container_name(container)
  527. for service in services:
  528. prefix = '%s_%s_%s' % (project, service, 'run_' if one_off else '')
  529. if not name.startswith(prefix):
  530. continue
  531. log.warn(
  532. "Compose found a found a container named %s without any "
  533. "labels. As of compose 1.3.0 containers are identified with "
  534. "labels instead of naming convention. If you'd like compose "
  535. "to use this container, please run "
  536. "`docker-compose --migrate-to-labels`" % (name,))
  537. def parse_restart_spec(restart_config):
  538. if not restart_config:
  539. return None
  540. parts = restart_config.split(':')
  541. if len(parts) > 2:
  542. raise ConfigError("Restart %s has incorrect format, should be "
  543. "mode[:max_retry]" % restart_config)
  544. if len(parts) == 2:
  545. name, max_retry_count = parts
  546. else:
  547. name, = parts
  548. max_retry_count = 0
  549. return {'Name': name, 'MaximumRetryCount': int(max_retry_count)}
  550. def parse_volume_spec(volume_config):
  551. parts = volume_config.split(':')
  552. if len(parts) > 3:
  553. raise ConfigError("Volume %s has incorrect format, should be "
  554. "external:internal[:mode]" % volume_config)
  555. if len(parts) == 1:
  556. return VolumeSpec(None, parts[0], 'rw')
  557. if len(parts) == 2:
  558. parts.append('rw')
  559. external, internal, mode = parts
  560. if mode not in ('rw', 'ro'):
  561. raise ConfigError("Volume %s has invalid mode (%s), should be "
  562. "one of: rw, ro." % (volume_config, mode))
  563. return VolumeSpec(external, internal, mode)
  564. def parse_repository_tag(s):
  565. if ":" not in s:
  566. return s, ""
  567. repo, tag = s.rsplit(":", 1)
  568. if "/" in tag:
  569. return s, ""
  570. return repo, tag
  571. def build_volume_binding(volume_spec):
  572. internal = {'bind': volume_spec.internal, 'ro': volume_spec.mode == 'ro'}
  573. return volume_spec.external, internal
  574. def build_port_bindings(ports):
  575. port_bindings = {}
  576. for port in ports:
  577. internal_port, external = split_port(port)
  578. if internal_port in port_bindings:
  579. port_bindings[internal_port].append(external)
  580. else:
  581. port_bindings[internal_port] = [external]
  582. return port_bindings
  583. def split_port(port):
  584. parts = str(port).split(':')
  585. if not 1 <= len(parts) <= 3:
  586. raise ConfigError('Invalid port "%s", should be '
  587. '[[remote_ip:]remote_port:]port[/protocol]' % port)
  588. if len(parts) == 1:
  589. internal_port, = parts
  590. return internal_port, None
  591. if len(parts) == 2:
  592. external_port, internal_port = parts
  593. return internal_port, external_port
  594. external_ip, external_port, internal_port = parts
  595. return internal_port, (external_ip, external_port or None)
  596. def build_extra_hosts(extra_hosts_config):
  597. if not extra_hosts_config:
  598. return {}
  599. if isinstance(extra_hosts_config, list):
  600. extra_hosts_dict = {}
  601. for extra_hosts_line in extra_hosts_config:
  602. if not isinstance(extra_hosts_line, six.string_types):
  603. raise ConfigError(
  604. "extra_hosts_config \"%s\" must be either a list of strings or a string->string mapping," %
  605. extra_hosts_config
  606. )
  607. host, ip = extra_hosts_line.split(':')
  608. extra_hosts_dict.update({host.strip(): ip.strip()})
  609. extra_hosts_config = extra_hosts_dict
  610. if isinstance(extra_hosts_config, dict):
  611. return extra_hosts_config
  612. raise ConfigError(
  613. "extra_hosts_config \"%s\" must be either a list of strings or a string->string mapping," %
  614. extra_hosts_config
  615. )