Skip to content

Commit

Permalink
Avoid creating duplicate mount points when recreating a service
Browse files Browse the repository at this point in the history
Signed-off-by: Joffrey F <[email protected]>
  • Loading branch information
shin- committed Oct 16, 2018
1 parent d821900 commit 4cb9229
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions compose/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,22 @@ def test_recreate_preserves_volume_with_trailing_slash(self):
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
Expand Down

0 comments on commit 4cb9229

Please sign in to comment.