Skip to content

Commit 3ff1f1e

Browse files
committed
Merge pull request docker#200 from ticosax/move-dns-and-volumes-from
From api 1.10 dns and volumes_from should be passed to start()
2 parents 0d2be16 + 88ee38b commit 3ff1f1e

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ to those for the `docker run` command except it doesn't support the
7171
attach options (`-a`). See "Port bindings" and "Using volumes" below for
7272
more information on how to create port bindings and volume mappings.
7373

74+
`volumes_from` and `dns` arguments raise TypeError exception if they are used
75+
against v1.10 of docker remote API. Those arguments should be passed to
76+
`start()` instead.
77+
78+
7479
```python
7580
c.diff(container)
7681
```
@@ -201,7 +206,8 @@ Identical to the `docker search` command.
201206

202207
```python
203208
c.start(container, binds=None, port_bindings=None, lxc_conf=None,
204-
publish_all_ports=False, links=None, privileged=False)
209+
publish_all_ports=False, links=None, privileged=False,
210+
dns=None, volumes_from=None)
205211
```
206212

207213
Similar to the `docker start` command, but doesn't support attach
@@ -218,6 +224,9 @@ can be specified with the `links` argument. They can either be
218224
specified as a dictionary mapping name to alias or as a list of
219225
`(name, alias)` tuples.
220226

227+
`dns` and `volumes_from` are only available if they are used with version v1.10
228+
of docker remote API. Otherwise they are ignored.
229+
221230
```python
222231
c.stop(container, timeout=10)
223232
```

docker/client.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import re
1717
import shlex
1818
import struct
19+
import warnings
1920

2021
import requests
2122
import requests.exceptions
@@ -141,6 +142,14 @@ def _container_config(self, image, command, hostname=None, user=None,
141142
attach_stdin = True
142143
stdin_once = True
143144

145+
if utils.compare_version('1.10', self._version) >= 0:
146+
message = ('{0!r} parameter has no effect on create_container().'
147+
' It has been moved to start()')
148+
if dns is not None:
149+
raise errors.DockerException(message.format('dns'))
150+
if volumes_from is not None:
151+
raise errors.DockerException(message.format('volumes_from'))
152+
144153
return {
145154
'Hostname': hostname,
146155
'Domainname': domainname,
@@ -669,7 +678,8 @@ def search(self, term):
669678
True)
670679

671680
def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
672-
publish_all_ports=False, links=None, privileged=False):
681+
publish_all_ports=False, links=None, privileged=False,
682+
dns=None, volumes_from=None):
673683
if isinstance(container, dict):
674684
container = container.get('Id')
675685

@@ -711,6 +721,25 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
711721

712722
start_config['Privileged'] = privileged
713723

724+
if utils.compare_version('1.10', self._version) >= 0:
725+
if dns is not None:
726+
start_config['Dns'] = dns
727+
if volumes_from is not None:
728+
if isinstance(volumes_from, six.string_types):
729+
volumes_from = volumes_from.split(',')
730+
start_config['VolumesFrom'] = volumes_from
731+
else:
732+
warning_message = ('{0!r} parameter is discarded. It is only'
733+
' available for API version greater or equal'
734+
' than 1.10')
735+
736+
if dns is not None:
737+
warnings.warn(warning_message.format('dns'),
738+
DeprecationWarning)
739+
if volumes_from is not None:
740+
warnings.warn(warning_message.format('volumes_from'),
741+
DeprecationWarning)
742+
714743
url = self._url("/containers/{0}/start".format(container))
715744
res = self._post_json(url, data=start_config)
716745
self._raise_for_status(res)

0 commit comments

Comments
 (0)