mirror of https://github.com/docker/docker-py.git
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:
parent
956fe1cac1
commit
f83993de0a
|
@ -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]
|
||||
|
|
|
@ -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'
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue