Merge pull request #623 from TFenby/capabilities

Add capability add/drop introduced in Docker 1.2
This commit is contained in:
Ben Firshman 2014-12-08 21:24:02 +00:00
commit 9a04ae0ddf
3 changed files with 31 additions and 3 deletions

View File

@ -142,6 +142,20 @@ dns:
- 9.9.9.9 - 9.9.9.9
``` ```
### cap_add, cap_drop
Add or drop container capabilities.
See `man 7 capabilities` for a full list.
```
cap_add:
- ALL
cap_drop:
- NET_ADMIN
- SYS_ADMIN
```
### working\_dir, entrypoint, user, hostname, domainname, mem\_limit, privileged, restart ### working\_dir, entrypoint, user, hostname, domainname, mem\_limit, privileged, restart
Each of these is a single value, analogous to its [docker run](https://docs.docker.com/reference/run/) counterpart. Each of these is a single value, analogous to its [docker run](https://docs.docker.com/reference/run/) counterpart.

View File

@ -15,7 +15,7 @@ from .progress_stream import stream_output, StreamOutputError
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
DOCKER_CONFIG_KEYS = ['image', 'command', 'hostname', 'domainname', 'user', 'detach', 'stdin_open', 'tty', 'mem_limit', 'ports', 'environment', 'dns', 'volumes', 'entrypoint', 'privileged', 'volumes_from', 'net', 'working_dir', 'restart'] DOCKER_CONFIG_KEYS = ['image', 'command', 'hostname', 'domainname', 'user', 'detach', 'stdin_open', 'tty', 'mem_limit', 'ports', 'environment', 'dns', 'volumes', 'entrypoint', 'privileged', 'volumes_from', 'net', 'working_dir', 'restart', 'cap_add', 'cap_drop']
DOCKER_CONFIG_HINTS = { DOCKER_CONFIG_HINTS = {
'link' : 'links', 'link' : 'links',
'port' : 'ports', 'port' : 'ports',
@ -261,6 +261,8 @@ class Service(object):
privileged = options.get('privileged', False) privileged = options.get('privileged', False)
net = options.get('net', 'bridge') net = options.get('net', 'bridge')
dns = options.get('dns', None) dns = options.get('dns', None)
cap_add = options.get('cap_add', None)
cap_drop = options.get('cap_drop', None)
restart = parse_restart_spec(options.get('restart', None)) restart = parse_restart_spec(options.get('restart', None))
@ -272,7 +274,9 @@ class Service(object):
privileged=privileged, privileged=privileged,
network_mode=net, network_mode=net,
dns=dns, dns=dns,
restart_policy=restart restart_policy=restart,
cap_add=cap_add,
cap_drop=cap_drop,
) )
return container return container
@ -379,7 +383,7 @@ class Service(object):
container_options['image'] = self._build_tag_name() container_options['image'] = self._build_tag_name()
# Delete options which are only used when starting # Delete options which are only used when starting
for key in ['privileged', 'net', 'dns', 'restart']: for key in ['privileged', 'net', 'dns', 'restart', 'cap_add', 'cap_drop']:
if key in container_options: if key in container_options:
del container_options[key] del container_options[key]

View File

@ -376,6 +376,16 @@ class ServiceTest(DockerClientTestCase):
self.assertEqual(container['HostConfig']['RestartPolicy']['Name'], 'on-failure') self.assertEqual(container['HostConfig']['RestartPolicy']['Name'], 'on-failure')
self.assertEqual(container['HostConfig']['RestartPolicy']['MaximumRetryCount'], 5) self.assertEqual(container['HostConfig']['RestartPolicy']['MaximumRetryCount'], 5)
def test_cap_add_list(self):
service = self.create_service('web', cap_add=['SYS_ADMIN', 'NET_ADMIN'])
container = service.start_container().inspect()
self.assertEqual(container['HostConfig']['CapAdd'], ['SYS_ADMIN', 'NET_ADMIN'])
def test_cap_drop_list(self):
service = self.create_service('web', cap_drop=['SYS_ADMIN', 'NET_ADMIN'])
container = service.start_container().inspect()
self.assertEqual(container['HostConfig']['CapDrop'], ['SYS_ADMIN', 'NET_ADMIN'])
def test_working_dir_param(self): def test_working_dir_param(self):
service = self.create_service('container', working_dir='/working/dir/sample') service = self.create_service('container', working_dir='/working/dir/sample')
container = service.create_container().inspect() container = service.create_container().inspect()