diff --git a/client/driver/docker.go b/client/driver/docker.go index 5372abbb525..df87a07d742 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -153,6 +153,7 @@ type DockerDriverConfig struct { Privileged bool `mapstructure:"privileged"` // Flag to run the container in privileged mode DNSServers []string `mapstructure:"dns_servers"` // DNS Server for containers DNSSearchDomains []string `mapstructure:"dns_search_domains"` // DNS Search domains for containers + DNSOptions []string `mapstructure:"dns_options"` // DNS Options ExtraHosts []string `mapstructure:"extra_hosts"` // Add host to /etc/hosts (host:IP) Hostname string `mapstructure:"hostname"` // Hostname for containers LabelsRaw []map[string]string `mapstructure:"labels"` // @@ -205,6 +206,7 @@ func NewDockerDriverConfig(task *structs.Task, env *env.TaskEnv) (*DockerDriverC dconf.VolumeDriver = env.ReplaceEnv(dconf.VolumeDriver) dconf.DNSServers = env.ParseAndReplace(dconf.DNSServers) dconf.DNSSearchDomains = env.ParseAndReplace(dconf.DNSSearchDomains) + dconf.DNSOptions = env.ParseAndReplace(dconf.DNSOptions) dconf.ExtraHosts = env.ParseAndReplace(dconf.ExtraHosts) dconf.MacAddress = env.ReplaceEnv(dconf.MacAddress) dconf.SecurityOpt = env.ParseAndReplace(dconf.SecurityOpt) @@ -409,6 +411,9 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error { "dns_servers": &fields.FieldSchema{ Type: fields.TypeArray, }, + "dns_options": &fields.FieldSchema{ + Type: fields.TypeArray, + }, "dns_search_domains": &fields.FieldSchema{ Type: fields.TypeArray, }, @@ -937,6 +942,7 @@ func (d *DockerDriver) createContainerConfig(ctx *ExecContext, task *structs.Tas // set DNS search domains and extra hosts hostConfig.DNSSearch = driverConfig.DNSSearchDomains + hostConfig.DNSOptions = driverConfig.DNSOptions hostConfig.ExtraHosts = driverConfig.ExtraHosts hostConfig.IpcMode = driverConfig.IpcMode diff --git a/client/driver/docker_test.go b/client/driver/docker_test.go index 496001ec132..f9524a34630 100644 --- a/client/driver/docker_test.go +++ b/client/driver/docker_test.go @@ -861,6 +861,7 @@ func TestDockerDriver_DNS(t *testing.T) { task, _, _ := dockerTask() task.Config["dns_servers"] = []string{"8.8.8.8", "8.8.4.4"} task.Config["dns_search_domains"] = []string{"example.com", "example.org", "example.net"} + task.Config["dns_options"] = []string{"ndots:1"} client, handle, cleanup := dockerSetup(t, task) defer cleanup() @@ -877,7 +878,11 @@ func TestDockerDriver_DNS(t *testing.T) { } if !reflect.DeepEqual(task.Config["dns_search_domains"], container.HostConfig.DNSSearch) { - t.Errorf("DNS Servers don't match.\nExpected:\n%s\nGot:\n%s\n", task.Config["dns_search_domains"], container.HostConfig.DNSSearch) + t.Errorf("DNS Search Domains don't match.\nExpected:\n%s\nGot:\n%s\n", task.Config["dns_search_domains"], container.HostConfig.DNSSearch) + } + + if !reflect.DeepEqual(task.Config["dns_options"], container.HostConfig.DNSOptions) { + t.Errorf("DNS Options don't match.\nExpected:\n%s\nGot:\n%s\n", task.Config["dns_options"], container.HostConfig.DNSOptions) } } diff --git a/website/source/docs/drivers/docker.html.md b/website/source/docs/drivers/docker.html.md index 192db51c8cd..44c5d6e4710 100644 --- a/website/source/docs/drivers/docker.html.md +++ b/website/source/docs/drivers/docker.html.md @@ -78,6 +78,8 @@ The `docker` driver supports the following configuration in the job spec. Only * `dns_search_domains` - (Optional) A list of DNS search domains for the container to use. +* `dns_options` - (Optional) A list of DNS options for the container to use. + * `dns_servers` - (Optional) A list of DNS servers for the container to use (e.g. ["8.8.8.8", "8.8.4.4"]). Requires Docker v1.10 or greater.