Merge pull request #34 from ehazlett/privileged-containers

added privileged container support
This commit is contained in:
Joffrey F 2013-08-30 10:28:22 -07:00
commit 6dff1efde7
3 changed files with 14 additions and 4 deletions

View File

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

View File

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

View File

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