Merge pull request #2821 from jpellerin/2820-fix-daemon-dns

Fixes #2820
This commit is contained in:
Michael Crosby 2013-12-02 18:19:31 -08:00
Родитель 650d4cc644 5a9cf7e754
Коммит 3ed0ff85f5
4 изменённых файлов: 39 добавлений и 4 удалений

Просмотреть файл

@ -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 != "" {

Просмотреть файл

@ -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)

10
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)
}

24
opts_unit_test.go Normal file
Просмотреть файл

@ -0,0 +1,24 @@
package docker
import (
"testing"
)
func TestValidateIP4(t *testing.T) {
if ret, err := ValidateIp4Address(`1.2.3.4`); err != nil || ret == "" {
t.Fatalf("ValidateIp4Address(`1.2.3.4`) got %s %s", ret, err)
}
if ret, err := ValidateIp4Address(`127.0.0.1`); err != nil || ret == "" {
t.Fatalf("ValidateIp4Address(`127.0.0.1`) got %s %s", ret, err)
}
if ret, err := ValidateIp4Address(`127`); err == nil || ret != "" {
t.Fatalf("ValidateIp4Address(`127`) got %s %s", ret, err)
}
if ret, err := ValidateIp4Address(`random invalid string`); err == nil || ret != "" {
t.Fatalf("ValidateIp4Address(`random invalid string`) got %s %s", ret, err)
}
}