Skip to content

Commit

Permalink
Handle volumes from the Dockerfile.
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
  • Loading branch information
dnephin committed Jan 21, 2015
1 parent c0c45a8 commit f7355be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 7 additions & 2 deletions compose/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,18 @@ def get_container_data_volumes(container, volumes_option):
a mapping of volume bindings for those volumes.
"""
volumes = []
for volume in volumes_option or []:

volumes_option = volumes_option or []
container_volumes = container.get('Volumes') or {}
original_volumes = set(volumes_option + container_volumes.keys())

for volume in original_volumes:
volume = parse_volume_spec(volume)
# No need to preserve host volumes
if volume.external:
continue

volume_path = (container.get('Volumes') or {}).get(volume.internal)
volume_path = container_volumes.get(volume.internal)
# New volume, doesn't exist in the old container
if not volume_path:
continue
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_recreate_containers_when_containers_are_stopped(self):

def test_recreate_containers_with_image_declared_volume(self):
service = Service(
project='figtest',
project='composetest',
name='db',
client=self.client,
build='tests/fixtures/dockerfile-with-volume',
Expand All @@ -193,9 +193,7 @@ def test_recreate_containers_with_image_declared_volume(self):
self.assertEqual(old_container.get('Volumes').keys(), ['/data'])
volume_path = old_container.get('Volumes')['/data']

service.recreate_containers()
new_container = service.containers()[0]
service.start_container(new_container)
new_container = service.recreate_containers()[0]
self.assertEqual(new_container.get('Volumes').keys(), ['/data'])
self.assertEqual(new_container.get('Volumes')['/data'], volume_path)

Expand Down

0 comments on commit f7355be

Please sign in to comment.