Skip to content

Commit

Permalink
Fix docker#5465 by catching a no-image exception in
Browse files Browse the repository at this point in the history
get_container_data_volumes. Added a case to the unit test to check that
an empty existing image doesn't result in an exception.

Signed-off-by: Ian Glen Neal <[email protected]>

Signed-off-by: Ian Glen Neal <[email protected]>
  • Loading branch information
iangneal committed Jan 11, 2018
1 parent b2d4d9f commit d0cc1a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
14 changes: 9 additions & 5 deletions compose/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -1310,17 +1310,21 @@ def get_container_data_volumes(container, volumes_option, tmpfs_option, mounts_o
"""
volumes = []
volumes_option = volumes_option or []
image_volumes = []

container_mounts = dict(
(mount['Destination'], mount)
for mount in container.get('Mounts') or {}
)

image_volumes = [
VolumeSpec.parse(volume)
for volume in
container.image_config['ContainerConfig'].get('Volumes') or {}
]
try:
image_volumes = [
VolumeSpec.parse(volume)
for volume in
container.image_config['ContainerConfig'].get('Volumes') or {}
]
except ImageNotFound:
return volumes

for volume in set(volumes_option + image_volumes):
# No need to preserve host volumes
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,14 @@ def test_get_container_data_volumes(self):
volumes, _ = get_container_data_volumes(container, options, ['/dev/tmpfs'], [])
assert sorted(volumes) == sorted(expected)

# Issue 5465, check for non-existant image.

container = Container(self.mock_client, {}, has_been_inspected=True)
expected = []

volumes, _ = get_container_data_volumes(container, options, ['/dev/tmpfs'], [])
assert sorted(volumes) == sorted(expected)

def test_merge_volume_bindings(self):
options = [
VolumeSpec.parse(v, True) for v in [
Expand Down

0 comments on commit d0cc1a7

Please sign in to comment.