mirror of
				https://github.com/docker/compose.git
				synced 2025-10-31 11:14:02 +01:00 
			
		
		
		
	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'): |         if not mount.get('Name'): | ||||||
|             continue |             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 |         # Copy existing volume from old container | ||||||
|         volume = volume._replace(external=mount['Name']) |         volume = volume._replace(external=mount['Name']) | ||||||
|         volumes.append(volume) |         volumes.append(volume) | ||||||
|  | |||||||
| @ -425,6 +425,22 @@ class ServiceTest(DockerClientTestCase): | |||||||
|         new_container = service.recreate_container(old_container) |         new_container = service.recreate_container(old_container) | ||||||
|         assert new_container.get_mount('/data')['Source'] == volume_path |         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): |     def test_duplicate_volume_trailing_slash(self): | ||||||
|         """ |         """ | ||||||
|         When an image specifies a volume, and the Compose file specifies a host path |         When an image specifies a volume, and the Compose file specifies a host path | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user