Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability add/drop introduced in Docker 1.2 #623

Merged
merged 1 commit into from
Dec 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ dns:
- 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

Each of these is a single value, analogous to its [docker run](https://docs.docker.com/reference/run/) counterpart.
Expand Down
10 changes: 7 additions & 3 deletions fig/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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 = {
'link' : 'links',
'port' : 'ports',
Expand Down Expand Up @@ -261,6 +261,8 @@ def start_container(self, container=None, intermediate_container=None, **overrid
privileged = options.get('privileged', False)
net = options.get('net', 'bridge')
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))

Expand All @@ -272,7 +274,9 @@ def start_container(self, container=None, intermediate_container=None, **overrid
privileged=privileged,
network_mode=net,
dns=dns,
restart_policy=restart
restart_policy=restart,
cap_add=cap_add,
cap_drop=cap_drop,
)
return container

Expand Down Expand Up @@ -379,7 +383,7 @@ def _get_container_create_options(self, override_options, one_off=False):
container_options['image'] = self._build_tag_name()

# 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:
del container_options[key]

Expand Down
10 changes: 10 additions & 0 deletions tests/integration/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,16 @@ def test_restart_on_failure_value(self):
self.assertEqual(container['HostConfig']['RestartPolicy']['Name'], 'on-failure')
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):
service = self.create_service('container', working_dir='/working/dir/sample')
container = service.create_container().inspect()
Expand Down