mirror of https://github.com/docker/docker-py.git
Merge branch 'named-container-create' of github.com:mpetazzoni/docker-py into mpetazzoni-named-container-create
This commit is contained in:
commit
78667c19a8
|
|
@ -26,7 +26,9 @@ Identical to the `docker ps` command.
|
||||||
* `c.copy(container, resource)`
|
* `c.copy(container, resource)`
|
||||||
Identical to the `docker cp` command.
|
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
|
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`)
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ class Client(requests.Session):
|
||||||
'Image': image,
|
'Image': image,
|
||||||
'Volumes': volumes,
|
'Volumes': volumes,
|
||||||
'VolumesFrom': volumes_from,
|
'VolumesFrom': volumes_from,
|
||||||
'Privileged': privileged,
|
'Privileged': privileged,
|
||||||
}
|
}
|
||||||
|
|
||||||
def _post_json(self, url, data, **kwargs):
|
def _post_json(self, url, data, **kwargs):
|
||||||
|
|
@ -263,17 +263,21 @@ class Client(requests.Session):
|
||||||
def create_container(self, image, command=None, hostname=None, user=None,
|
def create_container(self, image, command=None, hostname=None, user=None,
|
||||||
detach=False, stdin_open=False, tty=False,
|
detach=False, stdin_open=False, tty=False,
|
||||||
mem_limit=0, ports=None, environment=None, dns=None,
|
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(
|
config = self._container_config(
|
||||||
image, command, hostname, user, detach, stdin_open, tty, mem_limit,
|
image, command, hostname, user, detach, stdin_open, tty, mem_limit,
|
||||||
ports, environment, dns, volumes, volumes_from, privileged
|
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")
|
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)
|
return self._result(res, True)
|
||||||
|
|
||||||
def diff(self, container):
|
def diff(self, container):
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ class BaseTestCase(unittest.TestCase):
|
||||||
tmp_containers = []
|
tmp_containers = []
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = docker.Client()
|
self.client = docker.Client(version="1.6")
|
||||||
self.client.pull('busybox')
|
self.client.pull('busybox')
|
||||||
self.tmp_imgs = []
|
self.tmp_imgs = []
|
||||||
self.tmp_containers = []
|
self.tmp_containers = []
|
||||||
|
|
@ -168,6 +168,16 @@ class TestCreateContainerPrivileged(BaseTestCase):
|
||||||
self.assertEqual(inspect['Config']['Privileged'], True)
|
self.assertEqual(inspect['Config']['Privileged'], True)
|
||||||
|
|
||||||
|
|
||||||
|
class TestCreateContainerWithName(BaseTestCase):
|
||||||
|
def runTest(self):
|
||||||
|
res = self.client.create_container('busybox', 'true', name='foobar')
|
||||||
|
self.assertIn('Id', res)
|
||||||
|
self.tmp_containers.append(res['Id'])
|
||||||
|
inspect = self.client.inspect_container(res['Id'])
|
||||||
|
self.assertIn('Name', inspect)
|
||||||
|
self.assertEqual('/foobar', inspect['Name'])
|
||||||
|
|
||||||
|
|
||||||
class TestStartContainer(BaseTestCase):
|
class TestStartContainer(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res = self.client.create_container('busybox', 'true')
|
res = self.client.create_container('busybox', 'true')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue