mirror of https://github.com/docker/docker-py.git
Allow binds to be specified as a list of strings
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
be73aaf540
commit
1446b8c5ee
|
@ -174,6 +174,9 @@ def convert_port_bindings(port_bindings):
|
|||
|
||||
|
||||
def convert_volume_binds(binds):
|
||||
if isinstance(binds, list):
|
||||
return binds
|
||||
|
||||
result = []
|
||||
for k, v in binds.items():
|
||||
if isinstance(v, dict):
|
||||
|
|
|
@ -19,3 +19,16 @@ container_id = c.create_container(
|
|||
})
|
||||
)
|
||||
```
|
||||
|
||||
You can alternatively specify binds as a list. This code is equivalent to the
|
||||
example above:
|
||||
|
||||
```python
|
||||
container_id = c.create_container(
|
||||
'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'],
|
||||
host_config=docker.utils.create_host_config(binds=[
|
||||
'/home/user1/:/mnt/vol2',
|
||||
'/var/www:/mnt/vol1:ro',
|
||||
])
|
||||
)
|
||||
```
|
||||
|
|
|
@ -808,6 +808,36 @@ class DockerClientTest(Cleanup, base.BaseTestCase):
|
|||
DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_create_container_with_binds_list(self):
|
||||
try:
|
||||
self.client.create_container(
|
||||
'busybox', 'true', host_config=create_host_config(
|
||||
binds=[
|
||||
"/tmp:/mnt/1:ro",
|
||||
"/tmp:/mnt/2",
|
||||
],
|
||||
)
|
||||
)
|
||||
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/create')
|
||||
expected_payload = self.base_create_payload()
|
||||
expected_payload['HostConfig'] = create_host_config()
|
||||
expected_payload['HostConfig']['Binds'] = [
|
||||
"/tmp:/mnt/1:ro",
|
||||
"/tmp:/mnt/2",
|
||||
]
|
||||
self.assertEqual(json.loads(args[1]['data']), expected_payload)
|
||||
self.assertEqual(args[1]['headers'],
|
||||
{'Content-Type': 'application/json'})
|
||||
self.assertEqual(
|
||||
args[1]['timeout'],
|
||||
DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_create_container_with_port_binds(self):
|
||||
self.maxDiff = None
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue