mirror of https://github.com/docker/docker-py.git
commit
3aa51d52d0
15
README.md
15
README.md
|
|
@ -30,7 +30,12 @@ Identical to the `docker cp` command.
|
||||||
Creates a container that can then be `start`ed. Parameters are similar to those
|
Creates a container that can then be `start`ed. Parameters are similar to those
|
||||||
for the `docker run` command except it doesn't support the attach options
|
for the `docker run` command except it doesn't support the attach options
|
||||||
(`-a`)
|
(`-a`)
|
||||||
In order to create volumes that can be rebinded at start time, use the following syntax: `volumes={"/srv": "" }`
|
In order to create volumes that can be rebinded at start time, use the
|
||||||
|
following syntax: `volumes={"/srv": "" }`. The `ports` parameter is a
|
||||||
|
dictionary whose key is the port to expose and the value is an empty
|
||||||
|
dictionary: `ports={"2181/tcp": {}}`. Note, this will simply expose the ports in
|
||||||
|
the container, but does not make them available on the host. See `start`
|
||||||
|
below.
|
||||||
|
|
||||||
* `c.diff(container)`
|
* `c.diff(container)`
|
||||||
Identical to the `docker diff` command.
|
Identical to the `docker diff` command.
|
||||||
|
|
@ -94,13 +99,19 @@ Restart a container. Similar to the `docker restart` command.
|
||||||
* `c.search(term)`
|
* `c.search(term)`
|
||||||
Identical to the `docker search` command.
|
Identical to the `docker search` command.
|
||||||
|
|
||||||
* `c.start(container, binds=None, lxc_conf=None)`
|
* `c.start(container, binds=None, port_bindings=None, lxc_conf=None)`
|
||||||
Similar to the `docker start` command, but doesn't support attach options.
|
Similar to the `docker start` command, but doesn't support attach options.
|
||||||
Use `docker logs` to recover `stdout`/`stderr`
|
Use `docker logs` to recover `stdout`/`stderr`
|
||||||
`binds` Allows to bind a directory in the host to the container.
|
`binds` Allows to bind a directory in the host to the container.
|
||||||
Similar to the `docker run` command with option `-v="/host:/mnt"`.
|
Similar to the `docker run` command with option `-v="/host:/mnt"`.
|
||||||
Note that you must declare "blank" volumes at container creation to use binds.
|
Note that you must declare "blank" volumes at container creation to use binds.
|
||||||
Example of binds mapping from host to container: `{'/mnt/srv/': '/srv'}`
|
Example of binds mapping from host to container: `{'/mnt/srv/': '/srv'}`
|
||||||
|
`port_bindings` Exposes container ports to the host. This is a
|
||||||
|
dictionary whose key is the container's port and the value is a `[{'HostIp': ''
|
||||||
|
'HostPort': ''}]` list. Leaving `HostIp` blank will expose the port on
|
||||||
|
all host interfaces. By leaving the `HostPort` blank, Docker will
|
||||||
|
automatically assign a port. For example: `port_bindings={"2181/tcp": [{'HostIp': ''
|
||||||
|
'HostPort': ''}]}`.
|
||||||
`lxc_conf` allows to pass LXC configuration options in dict form.
|
`lxc_conf` allows to pass LXC configuration options in dict form.
|
||||||
|
|
||||||
* `c.stop(container, timeout=10)`
|
* `c.stop(container, timeout=10)`
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ class Client(requests.Session):
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'Hostname': hostname,
|
'Hostname': hostname,
|
||||||
'PortSpecs': ports,
|
'ExposedPorts': ports,
|
||||||
'User': user,
|
'User': user,
|
||||||
'Tty': tty,
|
'Tty': tty,
|
||||||
'OpenStdin': stdin_open,
|
'OpenStdin': stdin_open,
|
||||||
|
|
@ -445,7 +445,7 @@ class Client(requests.Session):
|
||||||
return self._result(self.get(self._url("/images/search"),
|
return self._result(self.get(self._url("/images/search"),
|
||||||
params={'term': term}), True)
|
params={'term': term}), True)
|
||||||
|
|
||||||
def start(self, container, binds=None, lxc_conf=None):
|
def start(self, container, binds=None, port_bindings=None, lxc_conf=None):
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
start_config = {
|
start_config = {
|
||||||
|
|
@ -457,6 +457,9 @@ class Client(requests.Session):
|
||||||
]
|
]
|
||||||
start_config['Binds'] = bind_pairs
|
start_config['Binds'] = bind_pairs
|
||||||
|
|
||||||
|
if port_bindings:
|
||||||
|
start_config['PortBindings'] = port_bindings
|
||||||
|
|
||||||
url = self._url("/containers/{0}/start".format(container))
|
url = self._url("/containers/{0}/start".format(container))
|
||||||
res = self._post_json(url, start_config)
|
res = self._post_json(url, start_config)
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue