mirror of https://github.com/docker/compose.git
Merge pull request #2706 from dnephin/dont_copy_host_volumes
Don't copy host volumes on recreate
This commit is contained in:
commit
883e45626f
|
@ -917,6 +917,10 @@ def get_container_data_volumes(container, volumes_option):
|
||||||
if not mount:
|
if not mount:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Volume was previously a host volume, now it's a container volume
|
||||||
|
if not mount.get('Name'):
|
||||||
|
continue
|
||||||
|
|
||||||
# Copy existing volume from old container
|
# Copy existing volume from old container
|
||||||
volume = volume._replace(external=mount['Source'])
|
volume = volume._replace(external=mount['Source'])
|
||||||
volumes.append(volume)
|
volumes.append(volume)
|
||||||
|
|
|
@ -343,6 +343,31 @@ class ServiceTest(DockerClientTestCase):
|
||||||
)
|
)
|
||||||
self.assertEqual(new_container.get_mount('/data')['Source'], volume_path)
|
self.assertEqual(new_container.get_mount('/data')['Source'], volume_path)
|
||||||
|
|
||||||
|
def test_execute_convergence_plan_when_host_volume_is_removed(self):
|
||||||
|
host_path = '/tmp/host-path'
|
||||||
|
service = self.create_service(
|
||||||
|
'db',
|
||||||
|
build={'context': 'tests/fixtures/dockerfile-with-volume'},
|
||||||
|
volumes=[VolumeSpec(host_path, '/data', 'rw')])
|
||||||
|
|
||||||
|
old_container = create_and_start_container(service)
|
||||||
|
assert (
|
||||||
|
[mount['Destination'] for mount in old_container.get('Mounts')] ==
|
||||||
|
['/data']
|
||||||
|
)
|
||||||
|
service.options['volumes'] = []
|
||||||
|
|
||||||
|
with mock.patch('compose.service.log', autospec=True) as mock_log:
|
||||||
|
new_container, = service.execute_convergence_plan(
|
||||||
|
ConvergencePlan('recreate', [old_container]))
|
||||||
|
|
||||||
|
assert not mock_log.warn.called
|
||||||
|
assert (
|
||||||
|
[mount['Destination'] for mount in new_container.get('Mounts')],
|
||||||
|
['/data']
|
||||||
|
)
|
||||||
|
assert new_container.get_mount('/data')['Source'] != host_path
|
||||||
|
|
||||||
def test_execute_convergence_plan_without_start(self):
|
def test_execute_convergence_plan_without_start(self):
|
||||||
service = self.create_service(
|
service = self.create_service(
|
||||||
'db',
|
'db',
|
||||||
|
|
Loading…
Reference in New Issue