Browse Source

Merge pull request #476 from salehe/dns-search

Add dns_search support in yml config
Daniel Nephin 11 years ago
parent
commit
cb1a5e0a24
3 changed files with 25 additions and 1 deletions
  1. 11 0
      docs/yml.md
  2. 4 1
      fig/service.py
  3. 10 0
      tests/integration/service_test.py

+ 11 - 0
docs/yml.md

@@ -171,6 +171,17 @@ cap_drop:
   - SYS_ADMIN
 ```
 
+### dns_search
+
+Custom DNS search domains. Can be a single value or a list.
+
+```
+dns_search: example.com
+dns_search:
+  - dc1.example.com
+  - dc2.example.com
+```
+
 ### 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.

+ 4 - 1
fig/service.py

@@ -21,6 +21,7 @@ DOCKER_CONFIG_KEYS = [
     'command',
     'detach',
     'dns',
+    'dns_search',
     'domainname',
     'entrypoint',
     'env_file',
@@ -284,6 +285,7 @@ class Service(object):
         privileged = options.get('privileged', False)
         net = options.get('net', 'bridge')
         dns = options.get('dns', None)
+        dns_search = options.get('dns_search', None)
         cap_add = options.get('cap_add', None)
         cap_drop = options.get('cap_drop', None)
 
@@ -297,6 +299,7 @@ class Service(object):
             privileged=privileged,
             network_mode=net,
             dns=dns,
+            dns_search=dns_search,
             restart_policy=restart,
             cap_add=cap_add,
             cap_drop=cap_drop,
@@ -407,7 +410,7 @@ class Service(object):
             container_options['image'] = self._get_image_name(container_options['image'])
 
         # Delete options which are only used when starting
-        for key in ['privileged', 'net', 'dns', 'restart', 'cap_add', 'cap_drop', 'env_file']:
+        for key in ['privileged', 'net', 'dns', 'dns_search', 'restart', 'cap_add', 'cap_drop', 'env_file']:
             if key in container_options:
                 del container_options[key]
 

+ 10 - 0
tests/integration/service_test.py

@@ -397,6 +397,16 @@ class ServiceTest(DockerClientTestCase):
         container = service.start_container().inspect()
         self.assertEqual(container['HostConfig']['CapDrop'], ['SYS_ADMIN', 'NET_ADMIN'])
 
+    def test_dns_search_single_value(self):
+        service = self.create_service('web', dns_search='example.com')
+        container = service.start_container().inspect()
+        self.assertEqual(container['HostConfig']['DnsSearch'], ['example.com'])
+
+    def test_dns_search_list(self):
+        service = self.create_service('web', dns_search=['dc1.example.com', 'dc2.example.com'])
+        container = service.start_container().inspect()
+        self.assertEqual(container['HostConfig']['DnsSearch'], ['dc1.example.com', 'dc2.example.com'])
+
     def test_working_dir_param(self):
         service = self.create_service('container', working_dir='/working/dir/sample')
         container = service.create_container().inspect()