Merge pull request #7506 from shykes/cleanup-daemonconfig

Cleanup: refactor parsing and handling of Daemon config
This commit is contained in:
Victor Vieux 2014-08-13 15:07:13 -07:00
commit 13eb477b62
17 changed files with 207 additions and 169 deletions

View File

@ -505,9 +505,6 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
if initPath := remoteInfo.Get("InitPath"); initPath != "" { if initPath := remoteInfo.Get("InitPath"); initPath != "" {
fmt.Fprintf(cli.out, "Init Path: %s\n", initPath) fmt.Fprintf(cli.out, "Init Path: %s\n", initPath)
} }
if len(remoteInfo.GetList("Sockets")) != 0 {
fmt.Fprintf(cli.out, "Sockets: %v\n", remoteInfo.GetList("Sockets"))
}
} }
if len(remoteInfo.GetList("IndexServerAddress")) != 0 { if len(remoteInfo.GetList("IndexServerAddress")) != 0 {
@ -1254,7 +1251,7 @@ func (cli *DockerCli) CmdImages(args ...string) error {
flViz := cmd.Bool([]string{"#v", "#viz", "#-viz"}, false, "Output graph in graphviz format") flViz := cmd.Bool([]string{"#v", "#viz", "#-viz"}, false, "Output graph in graphviz format")
flTree := cmd.Bool([]string{"#t", "#tree", "#-tree"}, false, "Output graph in tree format") flTree := cmd.Bool([]string{"#t", "#tree", "#-tree"}, false, "Output graph in tree format")
var flFilter opts.ListOpts flFilter := opts.NewListOpts(nil)
cmd.Var(&flFilter, []string{"f", "-filter"}, "Provide filter values (i.e. 'dangling=true')") cmd.Var(&flFilter, []string{"f", "-filter"}, "Provide filter values (i.e. 'dangling=true')")
if err := cmd.Parse(args); err != nil { if err := cmd.Parse(args); err != nil {
@ -1487,7 +1484,7 @@ func (cli *DockerCli) CmdPs(args ...string) error {
before := cmd.String([]string{"#beforeId", "#-before-id", "-before"}, "", "Show only container created before Id or Name, include non-running ones.") before := cmd.String([]string{"#beforeId", "#-before-id", "-before"}, "", "Show only container created before Id or Name, include non-running ones.")
last := cmd.Int([]string{"n"}, -1, "Show n last created containers, include non-running ones.") last := cmd.Int([]string{"n"}, -1, "Show n last created containers, include non-running ones.")
var flFilter opts.ListOpts flFilter := opts.NewListOpts(nil)
cmd.Var(&flFilter, []string{"f", "-filter"}, "Provide filter values. Valid filters:\nexited=<int> - containers with exit code of <int>") cmd.Var(&flFilter, []string{"f", "-filter"}, "Provide filter values. Valid filters:\nexited=<int> - containers with exit code of <int>")
if err := cmd.Parse(args); err != nil { if err := cmd.Parse(args); err != nil {

70
daemon/config.go Normal file
View File

@ -0,0 +1,70 @@
package daemon
import (
"net"
"github.com/docker/docker/daemon/networkdriver"
"github.com/docker/docker/opts"
flag "github.com/docker/docker/pkg/mflag"
)
const (
defaultNetworkMtu = 1500
DisableNetworkBridge = "none"
)
// Config define the configuration of a docker daemon
// These are the configuration settings that you pass
// to the docker daemon when you launch it with say: `docker -d -e lxc`
// FIXME: separate runtime configuration from http api configuration
type Config struct {
Pidfile string
Root string
AutoRestart bool
Dns []string
DnsSearch []string
EnableIptables bool
EnableIpForward bool
DefaultIp net.IP
BridgeIface string
BridgeIP string
InterContainerCommunication bool
GraphDriver string
GraphOptions []string
ExecDriver string
Mtu int
DisableNetwork bool
EnableSelinuxSupport bool
Context map[string][]string
}
// InstallFlags adds command-line options to the top-level flag parser for
// the current process.
// Subsequent calls to `flag.Parse` will populate config with values parsed
// from the command-line.
func (config *Config) InstallFlags() {
flag.StringVar(&config.Pidfile, []string{"p", "-pidfile"}, "/var/run/docker.pid", "Path to use for daemon PID file")
flag.StringVar(&config.Root, []string{"g", "-graph"}, "/var/lib/docker", "Path to use as the root of the Docker runtime")
flag.BoolVar(&config.AutoRestart, []string{"r", "-restart"}, true, "Restart previously running containers")
flag.BoolVar(&config.EnableIptables, []string{"#iptables", "-iptables"}, true, "Enable Docker's addition of iptables rules")
flag.BoolVar(&config.EnableIpForward, []string{"#ip-forward", "-ip-forward"}, true, "Enable net.ipv4.ip_forward")
flag.StringVar(&config.BridgeIP, []string{"#bip", "-bip"}, "", "Use this CIDR notation address for the network bridge's IP, not compatible with -b")
flag.StringVar(&config.BridgeIface, []string{"b", "-bridge"}, "", "Attach containers to a pre-existing network bridge\nuse 'none' to disable container networking")
flag.BoolVar(&config.InterContainerCommunication, []string{"#icc", "-icc"}, true, "Enable inter-container communication")
flag.StringVar(&config.GraphDriver, []string{"s", "-storage-driver"}, "", "Force the Docker runtime to use a specific storage driver")
flag.StringVar(&config.ExecDriver, []string{"e", "-exec-driver"}, "native", "Force the Docker runtime to use a specific exec driver")
flag.BoolVar(&config.EnableSelinuxSupport, []string{"-selinux-enabled"}, false, "Enable selinux support. SELinux does not presently support the BTRFS storage driver")
flag.IntVar(&config.Mtu, []string{"#mtu", "-mtu"}, 0, "Set the containers network MTU\nif no value is provided: default to the default route MTU or 1500 if no default route is available")
opts.IPVar(&config.DefaultIp, []string{"#ip", "-ip"}, "0.0.0.0", "Default IP address to use when binding container ports")
opts.ListVar(&config.GraphOptions, []string{"-storage-opt"}, "Set storage driver options")
// FIXME: why the inconsistency between "hosts" and "sockets"?
opts.IPListVar(&config.Dns, []string{"#dns", "-dns"}, "Force Docker to use specific DNS servers")
opts.DnsSearchListVar(&config.DnsSearch, []string{"-dns-search"}, "Force Docker to use specific DNS search domains")
}
func GetDefaultNetworkMtu() int {
if iface, err := networkdriver.GetDefaultRouteIface(); err == nil {
return iface.MTU
}
return defaultNetworkMtu
}

View File

@ -21,7 +21,6 @@ import (
_ "github.com/docker/docker/daemon/graphdriver/vfs" _ "github.com/docker/docker/daemon/graphdriver/vfs"
_ "github.com/docker/docker/daemon/networkdriver/bridge" _ "github.com/docker/docker/daemon/networkdriver/bridge"
"github.com/docker/docker/daemon/networkdriver/portallocator" "github.com/docker/docker/daemon/networkdriver/portallocator"
"github.com/docker/docker/daemonconfig"
"github.com/docker/docker/dockerversion" "github.com/docker/docker/dockerversion"
"github.com/docker/docker/engine" "github.com/docker/docker/engine"
"github.com/docker/docker/graph" "github.com/docker/docker/graph"
@ -95,11 +94,10 @@ type Daemon struct {
sysInfo *sysinfo.SysInfo sysInfo *sysinfo.SysInfo
volumes *graph.Graph volumes *graph.Graph
eng *engine.Engine eng *engine.Engine
config *daemonconfig.Config config *Config
containerGraph *graphdb.Database containerGraph *graphdb.Database
driver graphdriver.Driver driver graphdriver.Driver
execDriver execdriver.Driver execDriver execdriver.Driver
Sockets []string
} }
// Install installs daemon capabilities to eng. // Install installs daemon capabilities to eng.
@ -664,7 +662,7 @@ func (daemon *Daemon) RegisterLinks(container *Container, hostConfig *runconfig.
} }
// FIXME: harmonize with NewGraph() // FIXME: harmonize with NewGraph()
func NewDaemon(config *daemonconfig.Config, eng *engine.Engine) (*Daemon, error) { func NewDaemon(config *Config, eng *engine.Engine) (*Daemon, error) {
daemon, err := NewDaemonFromDirectory(config, eng) daemon, err := NewDaemonFromDirectory(config, eng)
if err != nil { if err != nil {
return nil, err return nil, err
@ -672,7 +670,22 @@ func NewDaemon(config *daemonconfig.Config, eng *engine.Engine) (*Daemon, error)
return daemon, nil return daemon, nil
} }
func NewDaemonFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*Daemon, error) { func NewDaemonFromDirectory(config *Config, eng *engine.Engine) (*Daemon, error) {
// Apply configuration defaults
if config.Mtu == 0 {
// FIXME: GetDefaultNetwork Mtu doesn't need to be public anymore
config.Mtu = GetDefaultNetworkMtu()
}
// Check for mutually incompatible config options
if config.BridgeIface != "" && config.BridgeIP != "" {
return nil, fmt.Errorf("You specified -b & --bip, mutually exclusive options. Please specify only one.")
}
if !config.EnableIptables && !config.InterContainerCommunication {
return nil, fmt.Errorf("You specified --iptables=false with --icc=false. ICC uses iptables to function. Please set --icc or --iptables to true.")
}
// FIXME: DisableNetworkBidge doesn't need to be public anymore
config.DisableNetwork = config.BridgeIface == DisableNetworkBridge
// Claim the pidfile first, to avoid any and all unexpected race conditions. // Claim the pidfile first, to avoid any and all unexpected race conditions.
// Some of the init doesn't need a pidfile lock - but let's not try to be smart. // Some of the init doesn't need a pidfile lock - but let's not try to be smart.
if config.Pidfile != "" { if config.Pidfile != "" {
@ -837,7 +850,6 @@ func NewDaemonFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*D
sysInitPath: sysInitPath, sysInitPath: sysInitPath,
execDriver: ed, execDriver: ed,
eng: eng, eng: eng,
Sockets: config.Sockets,
} }
if err := daemon.checkLocaldns(); err != nil { if err := daemon.checkLocaldns(); err != nil {
return nil, err return nil, err
@ -1010,7 +1022,7 @@ func (daemon *Daemon) Repositories() *graph.TagStore {
return daemon.repositories return daemon.repositories
} }
func (daemon *Daemon) Config() *daemonconfig.Config { func (daemon *Daemon) Config() *Config {
return daemon.config return daemon.config
} }

View File

@ -66,7 +66,6 @@ func (daemon *Daemon) CmdInfo(job *engine.Job) engine.Status {
v.Set("IndexServerAddress", registry.IndexServerAddress()) v.Set("IndexServerAddress", registry.IndexServerAddress())
v.Set("InitSha1", dockerversion.INITSHA1) v.Set("InitSha1", dockerversion.INITSHA1)
v.Set("InitPath", initPath) v.Set("InitPath", initPath)
v.SetList("Sockets", daemon.Sockets)
if _, err := v.WriteTo(job.Stdout); err != nil { if _, err := v.WriteTo(job.Stdout); err != nil {
return job.Error(err) return job.Error(err)
} }

View File

@ -1,3 +0,0 @@
This directory contains code pertaining to the configuration of the docker daemon
These are the configuration settings that you pass to the docker daemon when you launch it with say: `docker -d -e lxc`

View File

@ -1,41 +0,0 @@
package daemonconfig
import (
"github.com/docker/docker/daemon/networkdriver"
"net"
)
const (
defaultNetworkMtu = 1500
DisableNetworkBridge = "none"
)
// FIXME: separate runtime configuration from http api configuration
type Config struct {
Pidfile string
Root string
AutoRestart bool
Dns []string
DnsSearch []string
EnableIptables bool
EnableIpForward bool
DefaultIp net.IP
BridgeIface string
BridgeIP string
InterContainerCommunication bool
GraphDriver string
GraphOptions []string
ExecDriver string
Mtu int
DisableNetwork bool
EnableSelinuxSupport bool
Context map[string][]string
Sockets []string
}
func GetDefaultNetworkMtu() int {
if iface, err := networkdriver.GetDefaultRouteIface(); err == nil {
return iface.MTU
}
return defaultNetworkMtu
}

View File

@ -4,13 +4,11 @@ package main
import ( import (
"log" "log"
"net"
"github.com/docker/docker/builtins" "github.com/docker/docker/builtins"
"github.com/docker/docker/daemon" "github.com/docker/docker/daemon"
_ "github.com/docker/docker/daemon/execdriver/lxc" _ "github.com/docker/docker/daemon/execdriver/lxc"
_ "github.com/docker/docker/daemon/execdriver/native" _ "github.com/docker/docker/daemon/execdriver/native"
"github.com/docker/docker/daemonconfig"
"github.com/docker/docker/dockerversion" "github.com/docker/docker/dockerversion"
"github.com/docker/docker/engine" "github.com/docker/docker/engine"
flag "github.com/docker/docker/pkg/mflag" flag "github.com/docker/docker/pkg/mflag"
@ -19,24 +17,19 @@ import (
const CanDaemon = true const CanDaemon = true
var (
daemonCfg = &daemon.Config{}
)
func init() {
daemonCfg.InstallFlags()
}
func mainDaemon() { func mainDaemon() {
if flag.NArg() != 0 { if flag.NArg() != 0 {
flag.Usage() flag.Usage()
return return
} }
if *bridgeName != "" && *bridgeIp != "" {
log.Fatal("You specified -b & --bip, mutually exclusive options. Please specify only one.")
}
if !*flEnableIptables && !*flInterContainerComm {
log.Fatal("You specified --iptables=false with --icc=false. ICC uses iptables to function. Please set --icc or --iptables to true.")
}
if net.ParseIP(*flDefaultIp) == nil {
log.Fatalf("Specified --ip=%s is not in correct format \"0.0.0.0\".", *flDefaultIp)
}
eng := engine.New() eng := engine.New()
signal.Trap(eng.Shutdown) signal.Trap(eng.Shutdown)
// Load builtins // Load builtins
@ -48,34 +41,7 @@ func mainDaemon() {
// the http api so that connections don't fail while the daemon // the http api so that connections don't fail while the daemon
// is booting // is booting
go func() { go func() {
// FIXME: daemonconfig and CLI flag parsing should be directly integrated d, err := daemon.NewDaemon(daemonCfg, eng)
cfg := &daemonconfig.Config{
Pidfile: *pidfile,
Root: *flRoot,
AutoRestart: *flAutoRestart,
EnableIptables: *flEnableIptables,
EnableIpForward: *flEnableIpForward,
BridgeIP: *bridgeIp,
BridgeIface: *bridgeName,
DefaultIp: net.ParseIP(*flDefaultIp),
InterContainerCommunication: *flInterContainerComm,
GraphDriver: *flGraphDriver,
ExecDriver: *flExecDriver,
EnableSelinuxSupport: *flSelinuxEnabled,
GraphOptions: flGraphOpts.GetAll(),
Dns: flDns.GetAll(),
DnsSearch: flDnsSearch.GetAll(),
Mtu: *flMtu,
Sockets: flHosts.GetAll(),
}
// FIXME this should be initialized in NewDaemon or somewhere in daemonconfig.
// Currently it is copy-pasted in `integration` to create test daemons that work.
if cfg.Mtu == 0 {
cfg.Mtu = daemonconfig.GetDefaultNetworkMtu()
}
cfg.DisableNetwork = cfg.BridgeIface == daemonconfig.DisableNetworkBridge
d, err := daemon.NewDaemon(cfg, eng)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -92,11 +58,12 @@ func mainDaemon() {
log.Printf("docker daemon: %s %s; execdriver: %s; graphdriver: %s", log.Printf("docker daemon: %s %s; execdriver: %s; graphdriver: %s",
dockerversion.VERSION, dockerversion.VERSION,
dockerversion.GITCOMMIT, dockerversion.GITCOMMIT,
*flExecDriver, daemonCfg.ExecDriver,
*flGraphDriver) daemonCfg.GraphDriver,
)
// Serve api // Serve api
job := eng.Job("serveapi", flHosts.GetAll()...) job := eng.Job("serveapi", flHosts...)
job.SetenvBool("Logging", true) job.SetenvBool("Logging", true)
job.SetenvBool("EnableCors", *flEnableCors) job.SetenvBool("EnableCors", *flEnableCors)
job.Setenv("Version", dockerversion.VERSION) job.Setenv("Version", dockerversion.VERSION)

View File

@ -27,8 +27,8 @@ func main() {
if reexec.Init() { if reexec.Init() {
return return
} }
flag.Parse() flag.Parse()
// FIXME: validate daemon flags here
if *flVersion { if *flVersion {
showVersion() showVersion()
@ -38,7 +38,7 @@ func main() {
os.Setenv("DEBUG", "1") os.Setenv("DEBUG", "1")
} }
if flHosts.Len() == 0 { if len(flHosts) == 0 {
defaultHost := os.Getenv("DOCKER_HOST") defaultHost := os.Getenv("DOCKER_HOST")
if defaultHost == "" || *flDaemon { if defaultHost == "" || *flDaemon {
// If we do not have a host, default to unix socket // If we do not have a host, default to unix socket
@ -47,7 +47,7 @@ func main() {
if _, err := api.ValidateHost(defaultHost); err != nil { if _, err := api.ValidateHost(defaultHost); err != nil {
log.Fatal(err) log.Fatal(err)
} }
flHosts.Set(defaultHost) flHosts = append(flHosts, defaultHost)
} }
if *flDaemon { if *flDaemon {
@ -55,10 +55,10 @@ func main() {
return return
} }
if flHosts.Len() > 1 { if len(flHosts) > 1 {
log.Fatal("Please specify only one -H") log.Fatal("Please specify only one -H")
} }
protoAddrParts := strings.SplitN(flHosts.GetAll()[0], "://", 2) protoAddrParts := strings.SplitN(flHosts[0], "://", 2)
var ( var (
cli *client.DockerCli cli *client.DockerCli

View File

@ -4,7 +4,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/docker/docker/api"
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
flag "github.com/docker/docker/pkg/mflag" flag "github.com/docker/docker/pkg/mflag"
) )
@ -22,42 +21,22 @@ func init() {
var ( var (
flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit") flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit")
flDaemon = flag.Bool([]string{"d", "-daemon"}, false, "Enable daemon mode") flDaemon = flag.Bool([]string{"d", "-daemon"}, false, "Enable daemon mode")
flGraphOpts opts.ListOpts
flDebug = flag.Bool([]string{"D", "-debug"}, false, "Enable debug mode") flDebug = flag.Bool([]string{"D", "-debug"}, false, "Enable debug mode")
flAutoRestart = flag.Bool([]string{"r", "-restart"}, true, "Restart previously running containers")
bridgeName = flag.String([]string{"b", "-bridge"}, "", "Attach containers to a pre-existing network bridge\nuse 'none' to disable container networking")
bridgeIp = flag.String([]string{"#bip", "-bip"}, "", "Use this CIDR notation address for the network bridge's IP, not compatible with -b")
pidfile = flag.String([]string{"p", "-pidfile"}, "/var/run/docker.pid", "Path to use for daemon PID file")
flRoot = flag.String([]string{"g", "-graph"}, "/var/lib/docker", "Path to use as the root of the Docker runtime")
flSocketGroup = flag.String([]string{"G", "-group"}, "docker", "Group to assign the unix socket specified by -H when running in daemon mode\nuse '' (the empty string) to disable setting of a group") flSocketGroup = flag.String([]string{"G", "-group"}, "docker", "Group to assign the unix socket specified by -H when running in daemon mode\nuse '' (the empty string) to disable setting of a group")
flEnableCors = flag.Bool([]string{"#api-enable-cors", "-api-enable-cors"}, false, "Enable CORS headers in the remote API") flEnableCors = flag.Bool([]string{"#api-enable-cors", "-api-enable-cors"}, false, "Enable CORS headers in the remote API")
flDns = opts.NewListOpts(opts.ValidateIPAddress)
flDnsSearch = opts.NewListOpts(opts.ValidateDnsSearch)
flEnableIptables = flag.Bool([]string{"#iptables", "-iptables"}, true, "Enable Docker's addition of iptables rules")
flEnableIpForward = flag.Bool([]string{"#ip-forward", "-ip-forward"}, true, "Enable net.ipv4.ip_forward")
flDefaultIp = flag.String([]string{"#ip", "-ip"}, "0.0.0.0", "Default IP address to use when binding container ports")
flInterContainerComm = flag.Bool([]string{"#icc", "-icc"}, true, "Enable inter-container communication")
flGraphDriver = flag.String([]string{"s", "-storage-driver"}, "", "Force the Docker runtime to use a specific storage driver")
flExecDriver = flag.String([]string{"e", "-exec-driver"}, "native", "Force the Docker runtime to use a specific exec driver")
flHosts = opts.NewListOpts(api.ValidateHost)
flMtu = flag.Int([]string{"#mtu", "-mtu"}, 0, "Set the containers network MTU\nif no value is provided: default to the default route MTU or 1500 if no default route is available")
flTls = flag.Bool([]string{"-tls"}, false, "Use TLS; implied by tls-verify flags") flTls = flag.Bool([]string{"-tls"}, false, "Use TLS; implied by tls-verify flags")
flTlsVerify = flag.Bool([]string{"-tlsverify"}, false, "Use TLS and verify the remote (daemon: verify client, client: verify daemon)") flTlsVerify = flag.Bool([]string{"-tlsverify"}, false, "Use TLS and verify the remote (daemon: verify client, client: verify daemon)")
flSelinuxEnabled = flag.Bool([]string{"-selinux-enabled"}, false, "Enable selinux support. SELinux does not presently support the BTRFS storage driver")
// these are initialized in init() below since their default values depend on dockerCertPath which isn't fully initialized until init() runs // these are initialized in init() below since their default values depend on dockerCertPath which isn't fully initialized until init() runs
flCa *string flCa *string
flCert *string flCert *string
flKey *string flKey *string
flHosts []string
) )
func init() { func init() {
flCa = flag.String([]string{"-tlscacert"}, filepath.Join(dockerCertPath, defaultCaFile), "Trust only remotes providing a certificate signed by the CA given here") flCa = flag.String([]string{"-tlscacert"}, filepath.Join(dockerCertPath, defaultCaFile), "Trust only remotes providing a certificate signed by the CA given here")
flCert = flag.String([]string{"-tlscert"}, filepath.Join(dockerCertPath, defaultCertFile), "Path to TLS certificate file") flCert = flag.String([]string{"-tlscert"}, filepath.Join(dockerCertPath, defaultCertFile), "Path to TLS certificate file")
flKey = flag.String([]string{"-tlskey"}, filepath.Join(dockerCertPath, defaultKeyFile), "Path to TLS key file") flKey = flag.String([]string{"-tlskey"}, filepath.Join(dockerCertPath, defaultKeyFile), "Path to TLS key file")
opts.HostListVar(&flHosts, []string{"H", "-host"}, "The socket(s) to bind to in daemon mode\nspecified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.")
flag.Var(&flDns, []string{"#dns", "-dns"}, "Force Docker to use specific DNS servers")
flag.Var(&flDnsSearch, []string{"-dns-search"}, "Force Docker to use specific DNS search domains")
flag.Var(&flHosts, []string{"H", "-host"}, "The socket(s) to bind to in daemon mode\nspecified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.")
flag.Var(&flGraphOpts, []string{"-storage-opt"}, "Set storage driver options")
} }

View File

@ -1170,7 +1170,6 @@ Display system-wide information
"NGoroutines":21, "NGoroutines":21,
"NEventsListener":0, "NEventsListener":0,
"InitPath":"/usr/bin/docker", "InitPath":"/usr/bin/docker",
"Sockets":["unix:///var/run/docker.sock"],
"IndexServerAddress":["https://index.docker.io/v1/"], "IndexServerAddress":["https://index.docker.io/v1/"],
"MemoryLimit":true, "MemoryLimit":true,
"SwapLimit":false, "SwapLimit":false,

View File

@ -1174,7 +1174,6 @@ Display system-wide information
"NGoroutines":21, "NGoroutines":21,
"NEventsListener":0, "NEventsListener":0,
"InitPath":"/usr/bin/docker", "InitPath":"/usr/bin/docker",
"Sockets":["unix:///var/run/docker.sock"],
"IndexServerAddress":["https://index.docker.io/v1/"], "IndexServerAddress":["https://index.docker.io/v1/"],
"MemoryLimit":true, "MemoryLimit":true,
"SwapLimit":false, "SwapLimit":false,

View File

@ -616,7 +616,6 @@ For example:
Goroutines: 9 Goroutines: 9
EventsListeners: 0 EventsListeners: 0
Init Path: /usr/bin/docker Init Path: /usr/bin/docker
Sockets: [unix:///var/run/docker.sock]
Username: svendowideit Username: svendowideit
Registry: [https://index.docker.io/v1/] Registry: [https://index.docker.io/v1/]

View File

@ -17,7 +17,6 @@ import (
"github.com/docker/docker/builtins" "github.com/docker/docker/builtins"
"github.com/docker/docker/daemon" "github.com/docker/docker/daemon"
"github.com/docker/docker/daemonconfig"
"github.com/docker/docker/engine" "github.com/docker/docker/engine"
"github.com/docker/docker/runconfig" "github.com/docker/docker/runconfig"
"github.com/docker/docker/utils" "github.com/docker/docker/utils"
@ -179,17 +178,14 @@ func newTestEngine(t utils.Fataler, autorestart bool, root string) *engine.Engin
// Load default plugins // Load default plugins
builtins.Register(eng) builtins.Register(eng)
// (This is manually copied and modified from main() until we have a more generic plugin system) // (This is manually copied and modified from main() until we have a more generic plugin system)
cfg := &daemonconfig.Config{ cfg := &daemon.Config{
Root: root, Root: root,
AutoRestart: autorestart, AutoRestart: autorestart,
ExecDriver: "native", ExecDriver: "native",
// Either InterContainerCommunication or EnableIptables must be set,
// otherwise NewDaemon will fail because of conflicting settings.
InterContainerCommunication: true,
} }
// FIXME: this should be initialized in NewDaemon or somewhere in daemonconfig.
// Currently it is copy-pasted from daemonMain()
if cfg.Mtu == 0 {
cfg.Mtu = daemonconfig.GetDefaultNetworkMtu()
}
cfg.DisableNetwork = cfg.BridgeIface == daemonconfig.DisableNetworkBridge
d, err := daemon.NewDaemon(cfg, eng) d, err := daemon.NewDaemon(cfg, eng)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

31
opts/ip.go Normal file
View File

@ -0,0 +1,31 @@
package opts
import (
"fmt"
"net"
)
type IpOpt struct {
*net.IP
}
func NewIpOpt(ref *net.IP, defaultVal string) *IpOpt {
o := &IpOpt{
IP: ref,
}
o.Set(defaultVal)
return o
}
func (o *IpOpt) Set(val string) error {
ip := net.ParseIP(val)
if ip == nil {
return fmt.Errorf("%s is not an ip address", val)
}
(*o.IP) = net.ParseIP(val)
return nil
}
func (o *IpOpt) String() string {
return (*o.IP).String()
}

View File

@ -8,23 +8,51 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/docker/docker/api"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/parsers" "github.com/docker/docker/pkg/parsers"
) )
func ListVar(values *[]string, names []string, usage string) {
flag.Var(newListOptsRef(values, nil), names, usage)
}
func HostListVar(values *[]string, names []string, usage string) {
flag.Var(newListOptsRef(values, api.ValidateHost), names, usage)
}
func IPListVar(values *[]string, names []string, usage string) {
flag.Var(newListOptsRef(values, ValidateIPAddress), names, usage)
}
func DnsSearchListVar(values *[]string, names []string, usage string) {
flag.Var(newListOptsRef(values, ValidateDnsSearch), names, usage)
}
func IPVar(value *net.IP, names []string, defaultValue, usage string) {
flag.Var(NewIpOpt(value, defaultValue), names, usage)
}
// ListOpts type // ListOpts type
type ListOpts struct { type ListOpts struct {
values []string values *[]string
validator ValidatorFctType validator ValidatorFctType
} }
func NewListOpts(validator ValidatorFctType) ListOpts { func NewListOpts(validator ValidatorFctType) ListOpts {
return ListOpts{ var values []string
return *newListOptsRef(&values, validator)
}
func newListOptsRef(values *[]string, validator ValidatorFctType) *ListOpts {
return &ListOpts{
values: values,
validator: validator, validator: validator,
} }
} }
func (opts *ListOpts) String() string { func (opts *ListOpts) String() string {
return fmt.Sprintf("%v", []string(opts.values)) return fmt.Sprintf("%v", []string((*opts.values)))
} }
// Set validates if needed the input value and add it to the // Set validates if needed the input value and add it to the
@ -37,15 +65,15 @@ func (opts *ListOpts) Set(value string) error {
} }
value = v value = v
} }
opts.values = append(opts.values, value) (*opts.values) = append((*opts.values), value)
return nil return nil
} }
// Delete remove the given element from the slice. // Delete remove the given element from the slice.
func (opts *ListOpts) Delete(key string) { func (opts *ListOpts) Delete(key string) {
for i, k := range opts.values { for i, k := range *opts.values {
if k == key { if k == key {
opts.values = append(opts.values[:i], opts.values[i+1:]...) (*opts.values) = append((*opts.values)[:i], (*opts.values)[i+1:]...)
return return
} }
} }
@ -56,7 +84,7 @@ func (opts *ListOpts) Delete(key string) {
// FIXME: can we remove this? // FIXME: can we remove this?
func (opts *ListOpts) GetMap() map[string]struct{} { func (opts *ListOpts) GetMap() map[string]struct{} {
ret := make(map[string]struct{}) ret := make(map[string]struct{})
for _, k := range opts.values { for _, k := range *opts.values {
ret[k] = struct{}{} ret[k] = struct{}{}
} }
return ret return ret
@ -65,12 +93,12 @@ func (opts *ListOpts) GetMap() map[string]struct{} {
// GetAll returns the values' slice. // GetAll returns the values' slice.
// FIXME: Can we remove this? // FIXME: Can we remove this?
func (opts *ListOpts) GetAll() []string { func (opts *ListOpts) GetAll() []string {
return opts.values return (*opts.values)
} }
// Get checks the existence of the given key. // Get checks the existence of the given key.
func (opts *ListOpts) Get(key string) bool { func (opts *ListOpts) Get(key string) bool {
for _, k := range opts.values { for _, k := range *opts.values {
if k == key { if k == key {
return true return true
} }
@ -80,7 +108,7 @@ func (opts *ListOpts) Get(key string) bool {
// Len returns the amount of element in the slice. // Len returns the amount of element in the slice.
func (opts *ListOpts) Len() int { func (opts *ListOpts) Len() int {
return len(opts.values) return len((*opts.values))
} }
// Validators // Validators

View File

@ -27,6 +27,12 @@ func TestValidateIPAddress(t *testing.T) {
} }
func TestListOpts(t *testing.T) {
o := NewListOpts(nil)
o.Set("foo")
o.String()
}
func TestValidateDnsSearch(t *testing.T) { func TestValidateDnsSearch(t *testing.T) {
valid := []string{ valid := []string{
`.`, `.`,

View File

@ -45,15 +45,15 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
flEnv = opts.NewListOpts(opts.ValidateEnv) flEnv = opts.NewListOpts(opts.ValidateEnv)
flDevices = opts.NewListOpts(opts.ValidatePath) flDevices = opts.NewListOpts(opts.ValidatePath)
flPublish opts.ListOpts flPublish = opts.NewListOpts(nil)
flExpose opts.ListOpts flExpose = opts.NewListOpts(nil)
flDns = opts.NewListOpts(opts.ValidateIPAddress) flDns = opts.NewListOpts(opts.ValidateIPAddress)
flDnsSearch = opts.NewListOpts(opts.ValidateDnsSearch) flDnsSearch = opts.NewListOpts(opts.ValidateDnsSearch)
flVolumesFrom opts.ListOpts flVolumesFrom = opts.NewListOpts(nil)
flLxcOpts opts.ListOpts flLxcOpts = opts.NewListOpts(nil)
flEnvFile opts.ListOpts flEnvFile = opts.NewListOpts(nil)
flCapAdd opts.ListOpts flCapAdd = opts.NewListOpts(nil)
flCapDrop opts.ListOpts flCapDrop = opts.NewListOpts(nil)
flAutoRemove = cmd.Bool([]string{"#rm", "-rm"}, false, "Automatically remove the container when it exits (incompatible with -d)") flAutoRemove = cmd.Bool([]string{"#rm", "-rm"}, false, "Automatically remove the container when it exits (incompatible with -d)")
flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run container in the background and print new container ID") flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run container in the background and print new container ID")