mirror of https://github.com/docker/docker-py.git
fixes #175, fix flake8 erros
This commit is contained in:
parent
85ea42ecb3
commit
77fec67c60
12
README.md
12
README.md
|
@ -301,7 +301,15 @@ Volume mappings are then declared inside the `Client.start` method like this:
|
|||
|
||||
```python
|
||||
c.start(container_id, binds={
|
||||
'/home/user1/': '/mnt/vol2',
|
||||
'/var/www': '/mnt/vol1'
|
||||
'/home/user1/':
|
||||
{
|
||||
'bind': '/mnt/vol2',
|
||||
'ro': False
|
||||
},
|
||||
'/var/www':
|
||||
{
|
||||
'bind': '/mnt/vol1',
|
||||
'ro': True
|
||||
}
|
||||
})
|
||||
```
|
||||
|
|
|
@ -680,8 +680,12 @@ class Client(requests.Session):
|
|||
}
|
||||
if binds:
|
||||
bind_pairs = [
|
||||
'{0}:{1}'.format(host, dest) for host, dest in binds.items()
|
||||
'%s:%s:%s' % (
|
||||
h, d['bind'],
|
||||
'ro' if 'ro' in d and d['ro'] else 'rw'
|
||||
) for h, d in binds.items()
|
||||
]
|
||||
|
||||
start_config['Binds'] = bind_pairs
|
||||
|
||||
if port_bindings:
|
||||
|
|
|
@ -441,12 +441,15 @@ class DockerClientTest(unittest.TestCase):
|
|||
docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_start_container_with_binds(self):
|
||||
def test_start_container_with_binds_ro(self):
|
||||
try:
|
||||
mount_dest = '/mnt'
|
||||
mount_origin = '/tmp'
|
||||
self.client.start(fake_api.FAKE_CONTAINER_ID,
|
||||
binds={mount_origin: mount_dest})
|
||||
binds={mount_origin: {
|
||||
"bind": mount_dest,
|
||||
"ro": True
|
||||
}})
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
|
@ -454,7 +457,30 @@ class DockerClientTest(unittest.TestCase):
|
|||
self.assertEqual(args[0][0], url_prefix +
|
||||
'containers/3cc2351ab11b/start')
|
||||
self.assertEqual(json.loads(args[1]['data']),
|
||||
{"Binds": ["/tmp:/mnt"],
|
||||
{"Binds": ["/tmp:/mnt:ro"],
|
||||
"PublishAllPorts": False,
|
||||
"Privileged": False})
|
||||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
self.assertEqual(
|
||||
args[1]['timeout'],
|
||||
docker.client.DEFAULT_TIMEOUT_SECONDS)
|
||||
|
||||
def test_start_container_with_binds_rw(self):
|
||||
try:
|
||||
mount_dest = '/mnt'
|
||||
mount_origin = '/tmp'
|
||||
self.client.start(fake_api.FAKE_CONTAINER_ID,
|
||||
binds={mount_origin: {
|
||||
"bind": mount_dest, "ro": False}})
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
args = fake_request.call_args
|
||||
self.assertEqual(args[0][0], url_prefix +
|
||||
'containers/3cc2351ab11b/start')
|
||||
self.assertEqual(json.loads(args[1]['data']),
|
||||
{"Binds": ["/tmp:/mnt:rw"],
|
||||
"PublishAllPorts": False,
|
||||
"Privileged": False})
|
||||
self.assertEqual(args[1]['headers'],
|
||||
|
|
Loading…
Reference in New Issue