From ea087b7b151ee4b6697352a7e79425f8dbd5ba47 Mon Sep 17 00:00:00 2001 From: Evan Hazlett Date: Fri, 30 Aug 2013 09:35:09 -0400 Subject: [PATCH] added privileged container support --- README.md | 2 +- docker/client.py | 9 ++++++--- tests/test.py | 7 +++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2aa2735f..ec2e8f23 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Identical to the `docker commit` command. * `c.containers(quiet=False, all=False, trunc=True, latest=False, since=None, before=None, limit=-1)` Identical to the `docker ps` command. -* `c.create_container(image, command, 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)` +* `c.create_container(image, command, 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)` 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`) diff --git a/docker/client.py b/docker/client.py index 5f850b44..d20bc069 100644 --- a/docker/client.py +++ b/docker/client.py @@ -100,7 +100,8 @@ class Client(requests.Session): def _container_config(self, image, command, 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): + environment=None, dns=None, volumes=None, volumes_from=None, + privileged=False): if isinstance(command, six.string_types): command = shlex.split(str(command)) if isinstance(environment, dict): @@ -121,6 +122,7 @@ class Client(requests.Session): 'Image': image, 'Volumes': volumes, 'VolumesFrom': volumes_from, + 'Privileged': privileged, } def _mkbuildcontext(self, dockerfile): @@ -269,10 +271,11 @@ class Client(requests.Session): def create_container(self, image, command, 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): + environment=None, dns=None, volumes=None, volumes_from=None, + privileged=False): config = self._container_config(image, command, hostname, user, detach, stdin_open, tty, mem_limit, ports, environment, dns, - volumes, volumes_from) + volumes, volumes_from, privileged) return self.create_container_from_config(config) def create_container_from_config(self, config): diff --git a/tests/test.py b/tests/test.py index 3cd6f36f..026238fe 100644 --- a/tests/test.py +++ b/tests/test.py @@ -131,6 +131,13 @@ class TestCreateContainerWithBinds(BaseTestCase): os.unlink(shared_file) self.assertIn(filename, logs) +class TestCreateContainerPrivileged(BaseTestCase): + def runTest(self): + res = self.client.create_container('busybox', 'true', privileged=True) + inspect = self.client.inspect_container(res['Id']) + self.assertIn('Config', inspect) + self.assertEqual(inspect['Config']['Privileged'], True) + class TestStartContainer(BaseTestCase): def runTest(self): res = self.client.create_container('busybox', 'true')