Merge branch 'named-container-create' of github.com:mpetazzoni/docker-py into mpetazzoni-named-container-create

This commit is contained in:
shin- 2013-11-08 19:28:35 +01:00
commit 78667c19a8
3 changed files with 23 additions and 7 deletions

View File

@ -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`)

View File

@ -128,7 +128,7 @@ class Client(requests.Session):
'Image': image,
'Volumes': volumes,
'VolumesFrom': volumes_from,
'Privileged': privileged,
'Privileged': privileged,
}
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,
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):

View File

@ -30,7 +30,7 @@ class BaseTestCase(unittest.TestCase):
tmp_containers = []
def setUp(self):
self.client = docker.Client()
self.client = docker.Client(version="1.6")
self.client.pull('busybox')
self.tmp_imgs = []
self.tmp_containers = []
@ -168,6 +168,16 @@ class TestCreateContainerPrivileged(BaseTestCase):
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):
def runTest(self):
res = self.client.create_container('busybox', 'true')