mirror of https://github.com/docker/docker-py.git
Support naming containers when creating them
Add support for passing in the name parameter to the call to /containers/create to name the created container (API v1.6 feature). Signed-off-by: Maxime Petazzoni <max@signalfuse.com>
This commit is contained in:
parent
3aa51d52d0
commit
f344d8e65f
|
@ -26,7 +26,9 @@ Identical to the `docker ps` command.
|
|||
* `c.copy(container, resource)`
|
||||
Identical to the `docker cp` command.
|
||||
|
||||
* `c.create_container(image, command=None, hostname=None, user=None, detach=False,stdin_open=False, tty=False, mem_limit=0, ports=None, environment=None, dns=None,volumes=None, volumes_from=None, privileged=False)`
|
||||
* <code>c.create_container(image, command=None, hostname=None, user=None, detach=False,
|
||||
stdin_open=False, tty=False, mem_limit=0, ports=None, environment=None,
|
||||
dns=None, volumes=None, volumes_from=None, privileged=False, name=None)</code>
|
||||
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`)
|
||||
|
|
|
@ -125,7 +125,7 @@ class Client(requests.Session):
|
|||
'Image': image,
|
||||
'Volumes': volumes,
|
||||
'VolumesFrom': volumes_from,
|
||||
'Privileged': privileged,
|
||||
'Privileged': privileged,
|
||||
}
|
||||
|
||||
def _post_json(self, url, data, **kwargs):
|
||||
|
@ -242,17 +242,21 @@ class Client(requests.Session):
|
|||
def create_container(self, image, command=None, hostname=None, user=None,
|
||||
detach=False, stdin_open=False, tty=False,
|
||||
mem_limit=0, ports=None, environment=None, dns=None,
|
||||
volumes=None, volumes_from=None, privileged=False):
|
||||
volumes=None, volumes_from=None, privileged=False,
|
||||
name=None):
|
||||
|
||||
config = self._container_config(
|
||||
image, command, hostname, user, detach, stdin_open, tty, mem_limit,
|
||||
ports, environment, dns, volumes, volumes_from, privileged
|
||||
)
|
||||
return self.create_container_from_config(config)
|
||||
return self.create_container_from_config(config, name)
|
||||
|
||||
def create_container_from_config(self, config):
|
||||
def create_container_from_config(self, config, name=None):
|
||||
u = self._url("/containers/create")
|
||||
res = self._post_json(u, config)
|
||||
params = {
|
||||
'name': name
|
||||
}
|
||||
res = self._post_json(u, config, params=params)
|
||||
return self._result(res, True)
|
||||
|
||||
def diff(self, container):
|
||||
|
|
Loading…
Reference in New Issue