diff --git a/config.go b/config.go index eb00e41fa1..51d435b841 100644 --- a/config.go +++ b/config.go @@ -27,8 +27,8 @@ func ConfigFromJob(job *engine.Job) *DaemonConfig { config.Root = job.Getenv("Root") config.AutoRestart = job.GetenvBool("AutoRestart") config.EnableCors = job.GetenvBool("EnableCors") - if dns := job.Getenv("Dns"); dns != "" { - config.Dns = []string{dns} + if dns := job.GetenvList("Dns"); dns != nil { + config.Dns = dns } config.EnableIptables = job.GetenvBool("EnableIptables") if br := job.Getenv("BridgeIface"); br != "" { diff --git a/docker/docker.go b/docker/docker.go index ca829f3564..6e243f157f 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -33,13 +33,14 @@ func main() { pidfile = flag.String("p", "/var/run/docker.pid", "Path to use for daemon PID file") flRoot = flag.String("g", "/var/lib/docker", "Path to use as the root of the docker runtime") flEnableCors = flag.Bool("api-enable-cors", false, "Enable CORS headers in the remote API") - flDns = flag.String("dns", "", "Force docker to use specific DNS servers") + flDns = docker.NewListOpts(docker.ValidateIp4Address) flEnableIptables = flag.Bool("iptables", true, "Disable docker's addition of iptables rules") flDefaultIp = flag.String("ip", "0.0.0.0", "Default IP address to use when binding container ports") flInterContainerComm = flag.Bool("icc", true, "Enable inter-container communication") flGraphDriver = flag.String("s", "", "Force the docker runtime to use a specific storage driver") flHosts = docker.NewListOpts(docker.ValidateHost) ) + flag.Var(&flDns, "dns", "Force docker to use specific DNS servers") flag.Var(&flHosts, "H", "Multiple tcp://host:port or unix://path/to/socket to bind in daemon mode, single connection otherwise") flag.Parse() @@ -73,7 +74,7 @@ func main() { job.Setenv("Root", *flRoot) job.SetenvBool("AutoRestart", *flAutoRestart) job.SetenvBool("EnableCors", *flEnableCors) - job.Setenv("Dns", *flDns) + job.SetenvList("Dns", flDns.GetAll()) job.SetenvBool("EnableIptables", *flEnableIptables) job.Setenv("BridgeIface", *bridgeName) job.Setenv("DefaultIp", *flDefaultIp) diff --git a/opts.go b/opts.go index 80785a5161..ea5163e619 100644 --- a/opts.go +++ b/opts.go @@ -5,6 +5,7 @@ import ( "github.com/dotcloud/docker/utils" "os" "path/filepath" + "regexp" "strings" ) @@ -134,3 +135,12 @@ func ValidateHost(val string) (string, error) { } return host, nil } + +func ValidateIp4Address(val string) (string, error) { + re := regexp.MustCompile(`^(([0-9]+\.){3}([0-9]+))\s*$`) + var ns = re.FindSubmatch([]byte(val)) + if len(ns) > 0 { + return string(ns[1]), nil + } + return "", fmt.Errorf("%s is not an ip4 address", val) +}