From 140ced6a3bcdcb30d689a9518c4a8b941236f7d1 Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Thu, 17 Jul 2014 18:11:50 -0700 Subject: [PATCH] Fix and document `dns:` option Closes #240. Signed-off-by: Aanand Prasad --- docs/yml.md | 11 +++++++++++ fig/service.py | 13 ++++++------- tests/integration/service_test.py | 10 ++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/docs/yml.md b/docs/yml.md index 453e887d2..0bf267495 100644 --- a/docs/yml.md +++ b/docs/yml.md @@ -118,3 +118,14 @@ net: "none" net: "container:[name or id]" net: "host" ``` + +### dns + +Custom DNS servers. Can be a single value or a list. + +``` +dns: 8.8.8.8 +dns: + - 8.8.8.8 + - 9.9.9.9 +``` diff --git a/fig/service.py b/fig/service.py index ff2e99cf2..0d29a47c8 100644 --- a/fig/service.py +++ b/fig/service.py @@ -239,6 +239,7 @@ class Service(object): privileged = options.get('privileged', False) net = options.get('net', 'bridge') + dns = options.get('dns', None) container.start( links=self._get_links(link_to_self=override_options.get('one_off', False)), @@ -247,6 +248,7 @@ class Service(object): volumes_from=self._get_volumes_from(intermediate_container), privileged=privileged, network_mode=net, + dns=dns, ) return container @@ -347,13 +349,10 @@ class Service(object): self.build() container_options['image'] = self._build_tag_name() - # Priviliged is only required for starting containers, not for creating them - if 'privileged' in container_options: - del container_options['privileged'] - - # net is only required for starting containers, not for creating them - if 'net' in container_options: - del container_options['net'] + # Delete options which are only used when starting + for key in ['privileged', 'net', 'dns']: + if key in container_options: + del container_options[key] return container_options diff --git a/tests/integration/service_test.py b/tests/integration/service_test.py index ec936f881..937578f63 100644 --- a/tests/integration/service_test.py +++ b/tests/integration/service_test.py @@ -316,6 +316,16 @@ class ServiceTest(DockerClientTestCase): container = service.start_container().inspect() self.assertEqual(container['HostConfig']['NetworkMode'], 'host') + def test_dns_single_value(self): + service = self.create_service('web', dns='8.8.8.8') + container = service.start_container().inspect() + self.assertEqual(container['HostConfig']['Dns'], ['8.8.8.8']) + + def test_dns_list(self): + service = self.create_service('web', dns=['8.8.8.8', '9.9.9.9']) + container = service.start_container().inspect() + self.assertEqual(container['HostConfig']['Dns'], ['8.8.8.8', '9.9.9.9']) + def test_working_dir_param(self): service = self.create_service('container', working_dir='/working/dir/sample') container = service.create_container().inspect()