Merge pull request #76 from rca/port_bindings

Port bindings
This commit is contained in:
Joffrey F 2013-11-05 10:11:39 -08:00
commit 3aa51d52d0
2 changed files with 18 additions and 4 deletions

View File

@ -30,7 +30,12 @@ Identical to the `docker cp` command.
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
(`-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)`
Identical to the `docker diff` command.
@ -94,13 +99,19 @@ Restart a container. Similar to the `docker restart` command.
* `c.search(term)`
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.
Use `docker logs` to recover `stdout`/`stderr`
`binds` Allows to bind a directory in the host to the container.
Similar to the `docker run` command with option `-v="/host:/mnt"`.
Note that you must declare "blank" volumes at container creation to use binds.
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.
* `c.stop(container, timeout=10)`

View File

@ -111,7 +111,7 @@ class Client(requests.Session):
return {
'Hostname': hostname,
'PortSpecs': ports,
'ExposedPorts': ports,
'User': user,
'Tty': tty,
'OpenStdin': stdin_open,
@ -445,7 +445,7 @@ class Client(requests.Session):
return self._result(self.get(self._url("/images/search"),
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):
container = container.get('Id')
start_config = {
@ -457,6 +457,9 @@ class Client(requests.Session):
]
start_config['Binds'] = bind_pairs
if port_bindings:
start_config['PortBindings'] = port_bindings
url = self._url("/containers/{0}/start".format(container))
res = self._post_json(url, start_config)
self._raise_for_status(res)