Skip to content

Commit f044b5e

Browse files
committed
Merge branch 'master' of github.com:docker/docker-py
2 parents 62772b5 + 6dd3217 commit f044b5e

File tree

9 files changed

+236
-614
lines changed

9 files changed

+236
-614
lines changed

docker/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ def execute(self, container, cmd, detach=False, stdout=True, stderr=True,
526526
'exec_start instead', DeprecationWarning
527527
)
528528
create_res = self.exec_create(
529-
container, cmd, detach, stdout, stderr, tty
529+
container, cmd, stdout, stderr, tty
530530
)
531531

532532
return self.exec_start(create_res, detach, tty, stream)
@@ -730,7 +730,7 @@ def insert(self, image, url, path):
730730
raise errors.DeprecatedMethod(
731731
'insert is not available for API version >=1.12'
732732
)
733-
api_url = self._url("/images/{0}/insert".fornat(image))
733+
api_url = self._url("/images/{0}/insert".format(image))
734734
params = {
735735
'url': url,
736736
'path': path
@@ -1059,6 +1059,12 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
10591059
url = self._url("/containers/{0}/start".format(container))
10601060
if not start_config:
10611061
start_config = None
1062+
elif utils.compare_version('1.15', self._version) > 0:
1063+
warnings.warn(
1064+
'Passing host config parameters in start() is deprecated. '
1065+
'Please use host_config in create_container instead!',
1066+
DeprecationWarning
1067+
)
10621068
res = self._post_json(url, data=start_config)
10631069
self._raise_for_status(res)
10641070

docker/utils/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ def create_container_config(
577577
'Entrypoint': entrypoint,
578578
'CpuShares': cpu_shares,
579579
'Cpuset': cpuset,
580+
'CpusetCpus': cpuset,
580581
'WorkingDir': working_dir,
581582
'MemorySwap': memswap_limit,
582583
'HostConfig': host_config,

docs/api.md

Lines changed: 4 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ character, bytes are assumed as an intended unit.
188188
`volumes_from` and `dns` arguments raise [TypeError](
189189
https://docs.python.org/3.4/library/exceptions.html#TypeError) exception if
190190
they are used against v1.10 and above of the Docker remote API. Those
191-
arguments should be passed to `start()` instead, or as part of the `host_config`
192-
dictionary.
191+
arguments should be passed as part of the `host_config` dictionary.
193192

194193
**Params**:
195194

@@ -715,83 +714,9 @@ Identical to the `docker search` command.
715714
Similar to the `docker start` command, but doesn't support attach options. Use
716715
`.logs()` to recover `stdout`/`stderr`.
717716

718-
`binds` allows to bind a directory in the host to the container. See [Using
719-
volumes](volumes.md) for more information.
720-
721-
`port_bindings` exposes container ports to the host.
722-
See [Port bindings](port-bindings.md) for more information.
723-
724-
`lxc_conf` allows to pass LXC configuration options using a dictionary.
725-
726-
`privileged` starts the container in privileged mode.
727-
728-
[Links](http://docs.docker.io/en/latest/use/working_with_links_names/) can be
729-
specified with the `links` argument. They can either be specified as a
730-
dictionary mapping name to alias or as a list of `(name, alias)` tuples.
731-
732-
`dns` and `volumes_from` are only available if they are used with version v1.10
733-
of docker remote API. Otherwise they are ignored.
734-
735-
`network_mode` is available since v1.11 and sets the Network mode for the
736-
container ('bridge': creates a new network stack for the container on the
737-
Docker bridge, 'none': no networking for this container, 'container:[name|id]':
738-
reuses another container network stack), 'host': use the host network stack
739-
inside the container.
740-
741-
`restart_policy` is available since v1.2.0 and sets the RestartPolicy for how a
742-
container should or should not be restarted on exit. By default the policy is
743-
set to no meaning do not restart the container when it exits. The user may
744-
specify the restart policy as a dictionary for example:
745-
```python
746-
{
747-
"MaximumRetryCount": 0,
748-
"Name": "always"
749-
}
750-
```
751-
752-
For always restarting the container on exit or can specify to restart the
753-
container to restart on failure and can limit number of restarts. For example:
754-
```python
755-
{
756-
"MaximumRetryCount": 5,
757-
"Name": "on-failure"
758-
}
759-
```
760-
761-
`cap_add` and `cap_drop` are available since v1.2.0 and can be used to add or
762-
drop certain capabilities. The user may specify the capabilities as an array
763-
for example:
764-
```python
765-
[
766-
"SYS_ADMIN",
767-
"MKNOD"
768-
]
769-
```
770-
771-
**Params**:
772-
773-
* container (str): The container to start
774-
* binds: Volumes to bind
775-
* port_bindings (dict): Port bindings. See note above
776-
* lxc_conf (dict): LXC config
777-
* publish_all_ports (bool): Whether to publish all ports to the host
778-
* links (dict or list of tuples): See note above
779-
* privileged (bool): Give extended privileges to this container
780-
* dns (list): Set custom DNS servers
781-
* dns_search (list): DNS search domains
782-
* volumes_from (str or list): List of container names or Ids to get volumes
783-
from. Optionally a single string joining container id's with commas
784-
* network_mode (str): One of `['bridge', None, 'container:<name|id>',
785-
'host']`
786-
* restart_policy (dict): See note above. "Name" param must be one of
787-
`['on-failure', 'always']`
788-
* cap_add (list of str): See note above
789-
* cap_drop (list of str): See note above
790-
* extra_hosts (dict): custom host-to-IP mappings (host:ip)
791-
* pid_mode (str): if set to "host", use the host PID namespace inside the
792-
container
793-
* security_opt (list): A list of string values to customize labels for MLS systems, such as SELinux.
794-
* ulimits (list): A list of dicts or `docker.utils.Ulimit` objects.
717+
**Deprecation warning:** For API version > 1.15, it is highly recommended to
718+
provide host config options in the
719+
[`host_config` parameter of `create_container`](#create_container)
795720

796721
```python
797722
>>> from docker import Client

docs/host-devices.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
# Access to devices on the host
22

33
If you need to directly expose some host devices to a container, you can use
4-
the devices parameter in the `Client.start` method as shown below
4+
the devices parameter in the `host_config` param in `Client.create_container`
5+
as shown below:
56

67
```python
7-
c.start(container_id, devices=['/dev/sda:/dev/xvda:rwm'])
8+
c.create_container(
9+
'busybox', 'true', host_config=docker.utils.create_host_config(devices=[
10+
'/dev/sda:/dev/xvda:rwm'
11+
])
12+
)
813
```
914

1015
Each string is a single mapping using the colon (':') as the separator. So the

docs/hostconfig.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# HostConfig object
22

3-
The Docker Remote API introduced [support for HostConfig in version 1.15](http://docs.docker.com/reference/api/docker_remote_api_v1.15/#create-a-container). This object contains all the parameters you can pass to `Client.start`.
3+
The Docker Remote API introduced [support for HostConfig in version 1.15](http://docs.docker.com/reference/api/docker_remote_api_v1.15/#create-a-container). This object contains all the parameters you could previously pass to `Client.start`.
4+
*It is highly recommended that users pass the HostConfig in the `host_config`*
5+
*param of `Client.create_container` instead of `Client.start`*
46

57
## HostConfig helper
68

docs/port-bindings.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
# Port bindings
22
Port bindings is done in two parts. Firstly, by providing a list of ports to
33
open inside the container in the `Client().create_container()` method.
4+
Bindings are declared in the `host_config` parameter.
45

56
```python
6-
container_id = c.create_container('busybox', 'ls', ports=[1111, 2222])
7+
container_id = c.create_container(
8+
'busybox', 'ls', ports=[1111, 2222],
9+
host_config=docker.utils.create_host_config(port_bindings={
10+
1111: 4567,
11+
2222: None
12+
})
13+
)
714
```
815

9-
Bindings are then declared in the `Client.start` method.
10-
11-
```python
12-
c.start(container_id, port_bindings={1111: 4567, 2222: None})
13-
```
1416

1517
You can limit the host address on which the port will be exposed like such:
1618

1719
```python
18-
c.start(container_id, port_bindings={1111: ('127.0.0.1', 4567)})
20+
docker.utils.create_host_config(port_bindings={1111: ('127.0.0.1', 4567)})
1921
```
2022

2123
Or without host port assignment:
2224

2325
```python
24-
c.start(container_id, port_bindings={1111: ('127.0.0.1',)})
26+
docker.utils.create_host_config(port_bindings={1111: ('127.0.0.1',)})
2527
```
2628

27-
If you wish to use UDP instead of TCP (default), you need to declare it
28-
like such in both the `create_container()` and `start()` calls:
29+
If you wish to use UDP instead of TCP (default), you need to declare ports
30+
as such in both the config and host config:
2931

3032
```python
3133
container_id = c.create_container(
32-
'busybox',
33-
'ls',
34-
ports=[(1111, 'udp'), 2222]
34+
'busybox', 'ls', ports=[(1111, 'udp'), 2222],
35+
host_config=docker.utils.create_host_config(port_bindings={
36+
'1111/udp': 4567, 2222: None
37+
})
3538
)
36-
c.start(container_id, port_bindings={'1111/udp': 4567, 2222: None})
3739
```
38-

docs/volumes.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
# Using volumes
22

3-
Volume declaration is done in two parts. First, you have to provide
4-
a list of mountpoints to the `Client().create_container()` method.
3+
Volume declaration is done in two parts. Provide a list of mountpoints to
4+
the `Client().create_container()` method, and declare mappings in the
5+
`host_config` section.
56

67
```python
7-
container_id = c.create_container('busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'])
8-
```
9-
10-
Volume mappings are then declared inside the `Client.start` method like this:
11-
12-
```python
13-
c.start(container_id, binds={
14-
'/home/user1/':
15-
{
8+
container_id = c.create_container(
9+
'busybox', 'ls', volumes=['/mnt/vol1', '/mnt/vol2'],
10+
host_config=docker.utils.create_host_config(binds={
11+
'/home/user1/': {
1612
'bind': '/mnt/vol2',
1713
'ro': False
1814
},
19-
'/var/www':
20-
{
15+
'/var/www': {
2116
'bind': '/mnt/vol1',
2217
'ro': True
2318
}
24-
})
19+
})
20+
)
2521
```

0 commit comments

Comments
 (0)