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
|
```python
|
||||||
c.start(container_id, binds={
|
c.start(container_id, binds={
|
||||||
'/home/user1/': '/mnt/vol2',
|
'/home/user1/':
|
||||||
'/var/www': '/mnt/vol1'
|
{
|
||||||
|
'bind': '/mnt/vol2',
|
||||||
|
'ro': False
|
||||||
|
},
|
||||||
|
'/var/www':
|
||||||
|
{
|
||||||
|
'bind': '/mnt/vol1',
|
||||||
|
'ro': True
|
||||||
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -680,8 +680,12 @@ class Client(requests.Session):
|
||||||
}
|
}
|
||||||
if binds:
|
if binds:
|
||||||
bind_pairs = [
|
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
|
start_config['Binds'] = bind_pairs
|
||||||
|
|
||||||
if port_bindings:
|
if port_bindings:
|
||||||
|
|
|
||||||
|
|
@ -441,12 +441,15 @@ class DockerClientTest(unittest.TestCase):
|
||||||
docker.client.DEFAULT_TIMEOUT_SECONDS
|
docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_start_container_with_binds(self):
|
def test_start_container_with_binds_ro(self):
|
||||||
try:
|
try:
|
||||||
mount_dest = '/mnt'
|
mount_dest = '/mnt'
|
||||||
mount_origin = '/tmp'
|
mount_origin = '/tmp'
|
||||||
self.client.start(fake_api.FAKE_CONTAINER_ID,
|
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:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(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 +
|
self.assertEqual(args[0][0], url_prefix +
|
||||||
'containers/3cc2351ab11b/start')
|
'containers/3cc2351ab11b/start')
|
||||||
self.assertEqual(json.loads(args[1]['data']),
|
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,
|
"PublishAllPorts": False,
|
||||||
"Privileged": False})
|
"Privileged": False})
|
||||||
self.assertEqual(args[1]['headers'],
|
self.assertEqual(args[1]['headers'],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue