|
@@ -785,6 +785,35 @@ class Service(object):
|
|
|
self.options.get('labels'),
|
|
|
override_options.get('labels'))
|
|
|
|
|
|
+ container_options, override_options = self._build_container_volume_options(
|
|
|
+ previous_container, container_options, override_options
|
|
|
+ )
|
|
|
+
|
|
|
+ container_options['image'] = self.image_name
|
|
|
+
|
|
|
+ container_options['labels'] = build_container_labels(
|
|
|
+ container_options.get('labels', {}),
|
|
|
+ self.labels(one_off=one_off),
|
|
|
+ number,
|
|
|
+ self.config_hash if add_config_hash else None)
|
|
|
+
|
|
|
+ # Delete options which are only used in HostConfig
|
|
|
+ for key in HOST_CONFIG_KEYS:
|
|
|
+ container_options.pop(key, None)
|
|
|
+
|
|
|
+ container_options['host_config'] = self._get_container_host_config(
|
|
|
+ override_options,
|
|
|
+ one_off=one_off)
|
|
|
+
|
|
|
+ networking_config = self.build_default_networking_config()
|
|
|
+ if networking_config:
|
|
|
+ container_options['networking_config'] = networking_config
|
|
|
+
|
|
|
+ container_options['environment'] = format_environment(
|
|
|
+ container_options['environment'])
|
|
|
+ return container_options
|
|
|
+
|
|
|
+ def _build_container_volume_options(self, previous_container, container_options, override_options):
|
|
|
container_volumes = []
|
|
|
container_mounts = []
|
|
|
if 'volumes' in container_options:
|
|
@@ -801,7 +830,11 @@ class Service(object):
|
|
|
container_options['environment'].update(affinity)
|
|
|
|
|
|
container_options['volumes'] = dict((v.internal, {}) for v in container_volumes or {})
|
|
|
- override_options['mounts'] = [build_mount(v) for v in container_mounts] or None
|
|
|
+ if version_gte(self.client.api_version, '1.30'):
|
|
|
+ override_options['mounts'] = [build_mount(v) for v in container_mounts] or None
|
|
|
+ else:
|
|
|
+ override_options['binds'].extend(m.legacy_repr() for m in container_mounts)
|
|
|
+ container_options['volumes'].update((m.target, {}) for m in container_mounts)
|
|
|
|
|
|
secret_volumes = self.get_secret_volumes()
|
|
|
if secret_volumes:
|
|
@@ -814,29 +847,7 @@ class Service(object):
|
|
|
override_options['mounts'] = override_options.get('mounts') or []
|
|
|
override_options['mounts'].extend([build_mount(v) for v in secret_volumes])
|
|
|
|
|
|
- container_options['image'] = self.image_name
|
|
|
-
|
|
|
- container_options['labels'] = build_container_labels(
|
|
|
- container_options.get('labels', {}),
|
|
|
- self.labels(one_off=one_off),
|
|
|
- number,
|
|
|
- self.config_hash if add_config_hash else None)
|
|
|
-
|
|
|
- # Delete options which are only used in HostConfig
|
|
|
- for key in HOST_CONFIG_KEYS:
|
|
|
- container_options.pop(key, None)
|
|
|
-
|
|
|
- container_options['host_config'] = self._get_container_host_config(
|
|
|
- override_options,
|
|
|
- one_off=one_off)
|
|
|
-
|
|
|
- networking_config = self.build_default_networking_config()
|
|
|
- if networking_config:
|
|
|
- container_options['networking_config'] = networking_config
|
|
|
-
|
|
|
- container_options['environment'] = format_environment(
|
|
|
- container_options['environment'])
|
|
|
- return container_options
|
|
|
+ return container_options, override_options
|
|
|
|
|
|
def _get_container_host_config(self, override_options, one_off=False):
|
|
|
options = dict(self.options, **override_options)
|