mirror of https://github.com/docker/compose.git
Avoid creating duplicate mount points when recreating a service
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
d82190025a
commit
4cb92294a3
|
@ -1491,6 +1491,11 @@ def get_container_data_volumes(container, volumes_option, tmpfs_option, mounts_o
|
|||
if not mount.get('Name'):
|
||||
continue
|
||||
|
||||
# Volume (probably an image volume) is overridden by a mount in the service's config
|
||||
# and would cause a duplicate mountpoint error
|
||||
if volume.internal in [m.target for m in mounts_option]:
|
||||
continue
|
||||
|
||||
# Copy existing volume from old container
|
||||
volume = volume._replace(external=mount['Name'])
|
||||
volumes.append(volume)
|
||||
|
|
|
@ -425,6 +425,22 @@ class ServiceTest(DockerClientTestCase):
|
|||
new_container = service.recreate_container(old_container)
|
||||
assert new_container.get_mount('/data')['Source'] == volume_path
|
||||
|
||||
def test_recreate_volume_to_mount(self):
|
||||
# https://github.com/docker/compose/issues/6280
|
||||
service = Service(
|
||||
project='composetest',
|
||||
name='db',
|
||||
client=self.client,
|
||||
build={'context': 'tests/fixtures/dockerfile-with-volume'},
|
||||
volumes=[MountSpec.parse({
|
||||
'type': 'volume',
|
||||
'target': '/data',
|
||||
})]
|
||||
)
|
||||
old_container = create_and_start_container(service)
|
||||
new_container = service.recreate_container(old_container)
|
||||
assert new_container.get_mount('/data')['Source']
|
||||
|
||||
def test_duplicate_volume_trailing_slash(self):
|
||||
"""
|
||||
When an image specifies a volume, and the Compose file specifies a host path
|
||||
|
|
Loading…
Reference in New Issue