Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions docs/volumes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])
)
```
30 changes: 30 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,36 @@ def test_create_container_with_binds_rw(self):
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:
Expand Down