Fix passing volumes to run with no host path

Technically we shouldn't be passing them as binds, but the daemon
doesn't seem to mind.

Fixes #1380

Signed-off-by: Ben Firshman <ben@firshman.co.uk>
This commit is contained in:
Ben Firshman 2017-02-07 17:03:02 +01:00
parent 956fe1cac1
commit f83993de0a
No known key found for this signature in database
GPG Key ID: 18296449E36D2F1E
2 changed files with 22 additions and 2 deletions

View File

@ -885,5 +885,15 @@ def _create_container_args(kwargs):
for p in sorted(port_bindings.keys())]
binds = create_kwargs['host_config'].get('Binds')
if binds:
create_kwargs['volumes'] = [v.split(':')[1] for v in binds]
create_kwargs['volumes'] = [_host_volume_from_bind(v) for v in binds]
return create_kwargs
def _host_volume_from_bind(bind):
bits = bind.split(':')
if len(bits) == 1:
return bits[0]
elif len(bits) == 2 and bits[1] in ('ro', 'rw'):
return bits[0]
else:
return bits[1]

View File

@ -101,6 +101,8 @@ class ContainerCollectionTest(unittest.TestCase):
'/home/user1/:/mnt/vol2',
'/var/www:/mnt/vol1:ro',
'volumename:/mnt/vol3',
'/volumewithnohostpath',
'/anothervolumewithnohostpath:ro',
],
volumes_from=['container'],
working_dir='/code'
@ -118,6 +120,8 @@ class ContainerCollectionTest(unittest.TestCase):
'/home/user1/:/mnt/vol2',
'/var/www:/mnt/vol1:ro',
'volumename:/mnt/vol3',
'/volumewithnohostpath',
'/anothervolumewithnohostpath:ro'
],
'BlkioDeviceReadBps': [{'Path': 'foo', 'Rate': 3}],
'BlkioDeviceReadIOps': [{'Path': 'foo', 'Rate': 3}],
@ -183,7 +187,13 @@ class ContainerCollectionTest(unittest.TestCase):
tty=True,
user='bob',
volume_driver='some_driver',
volumes=['/mnt/vol2', '/mnt/vol1', '/mnt/vol3'],
volumes=[
'/mnt/vol2',
'/mnt/vol1',
'/mnt/vol3',
'/volumewithnohostpath',
'/anothervolumewithnohostpath'
],
working_dir='/code'
)