summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAanand Prasad <aanand.prasad@gmail.com>2015-06-12 12:36:59 -0400
committerAanand Prasad <aanand.prasad@gmail.com>2015-06-12 12:36:59 -0400
commit1446b8c5eef57bb5f7392f73fada9ba4dc305de9 (patch)
tree52e3c1f0988e77e18b0283b4a32293594cafbc58
parentbe73aaf5401faf5ca64911fb6664036c7b7ec61b (diff)
downloaddocker-py-1446b8c5eef57bb5f7392f73fada9ba4dc305de9.tar.gz
Allow binds to be specified as a list of strings
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
-rw-r--r--docker/utils/utils.py3
-rw-r--r--docs/volumes.md13
-rw-r--r--tests/test.py30
3 files changed, 46 insertions, 0 deletions
diff --git a/docker/utils/utils.py b/docker/utils/utils.py
index e4a3c9e..724af46 100644
--- a/docker/utils/utils.py
+++ b/docker/utils/utils.py
@@ -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):
diff --git a/docs/volumes.md b/docs/volumes.md
index de28214..db42155 100644
--- a/docs/volumes.md
+++ b/docs/volumes.md
@@ -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',
+ ])
+)
+```
diff --git a/tests/test.py b/tests/test.py
index e0a9e34..97af11e 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -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: