Browse Source

Use daemon exec root for swarm control socket

Right now docker puts swarm's control socket into the docker root dir
(e.g. /var/lib/docker).
This can cause some nasty issues with path length being > 108
characters, especially in our CI environment.

Since we already have some other state going in the daemon's exec root
(libcontainerd and libnetwork), I think it makes sense to move the
control socket to this location, especially since there are other unix
sockets being created here by docker so it must always be at a path that
works.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Brian Goff 9 years ago
parent
commit
4d95ea319c

+ 1 - 0
cmd/dockerd/daemon.go

@@ -275,6 +275,7 @@ func (cli *DaemonCli) start() (err error) {
 		Backend:                d,
 		Backend:                d,
 		NetworkSubnetsProvider: d,
 		NetworkSubnetsProvider: d,
 		DefaultAdvertiseAddr:   cli.Config.SwarmDefaultAdvertiseAddr,
 		DefaultAdvertiseAddr:   cli.Config.SwarmDefaultAdvertiseAddr,
+		RuntimeRoot:            cli.getSwarmRunRoot(),
 	})
 	})
 	if err != nil {
 	if err != nil {
 		logrus.Fatalf("Error creating cluster component: %v", err)
 		logrus.Fatalf("Error creating cluster component: %v", err)

+ 6 - 0
cmd/dockerd/daemon_solaris.go

@@ -61,6 +61,12 @@ func (cli *DaemonCli) getLibcontainerdRoot() string {
 	return filepath.Join(cli.Config.ExecRoot, "libcontainerd")
 	return filepath.Join(cli.Config.ExecRoot, "libcontainerd")
 }
 }
 
 
+// getSwarmRunRoot gets the root directory for swarm to store runtime state
+// For example, the control socket
+func (cli *DaemonCli) getSwarmRunRoot() string {
+	return filepath.Join(cli.Config.ExecRoot, "swarm")
+}
+
 func allocateDaemonPort(addr string) error {
 func allocateDaemonPort(addr string) error {
 	return nil
 	return nil
 }
 }

+ 6 - 0
cmd/dockerd/daemon_unix.go

@@ -85,6 +85,12 @@ func (cli *DaemonCli) getLibcontainerdRoot() string {
 	return filepath.Join(cli.Config.ExecRoot, "libcontainerd")
 	return filepath.Join(cli.Config.ExecRoot, "libcontainerd")
 }
 }
 
 
+// getSwarmRunRoot gets the root directory for swarm to store runtime state
+// For example, the control socket
+func (cli *DaemonCli) getSwarmRunRoot() string {
+	return filepath.Join(cli.Config.ExecRoot, "swarm")
+}
+
 // allocateDaemonPort ensures that there are no containers
 // allocateDaemonPort ensures that there are no containers
 // that try to use any port allocated for the docker server.
 // that try to use any port allocated for the docker server.
 func allocateDaemonPort(addr string) error {
 func allocateDaemonPort(addr string) error {

+ 6 - 0
cmd/dockerd/daemon_windows.go

@@ -73,6 +73,12 @@ func (cli *DaemonCli) getLibcontainerdRoot() string {
 	return ""
 	return ""
 }
 }
 
 
+// getSwarmRunRoot gets the root directory for swarm to store runtime state
+// For example, the control socket
+func (cli *DaemonCli) getSwarmRunRoot() string {
+	return ""
+}
+
 func allocateDaemonPort(addr string) error {
 func allocateDaemonPort(addr string) error {
 	return nil
 	return nil
 }
 }

+ 12 - 1
daemon/cluster/cluster.go

@@ -103,6 +103,9 @@ type Config struct {
 	// DefaultAdvertiseAddr is the default host/IP or network interface to use
 	// DefaultAdvertiseAddr is the default host/IP or network interface to use
 	// if no AdvertiseAddr value is specified.
 	// if no AdvertiseAddr value is specified.
 	DefaultAdvertiseAddr string
 	DefaultAdvertiseAddr string
+
+	// path to store runtime state, such as the swarm control socket
+	RuntimeRoot string
 }
 }
 
 
 // Cluster provides capabilities to participate in a cluster as a worker or a
 // Cluster provides capabilities to participate in a cluster as a worker or a
@@ -111,6 +114,7 @@ type Cluster struct {
 	sync.RWMutex
 	sync.RWMutex
 	*node
 	*node
 	root            string
 	root            string
+	runtimeRoot     string
 	config          Config
 	config          Config
 	configEvent     chan struct{} // todo: make this array and goroutine safe
 	configEvent     chan struct{} // todo: make this array and goroutine safe
 	localAddr       string
 	localAddr       string
@@ -138,10 +142,17 @@ func New(config Config) (*Cluster, error) {
 	if err := os.MkdirAll(root, 0700); err != nil {
 	if err := os.MkdirAll(root, 0700); err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
+	if config.RuntimeRoot == "" {
+		config.RuntimeRoot = root
+	}
+	if err := os.MkdirAll(config.RuntimeRoot, 0700); err != nil {
+		return nil, err
+	}
 	c := &Cluster{
 	c := &Cluster{
 		root:        root,
 		root:        root,
 		config:      config,
 		config:      config,
 		configEvent: make(chan struct{}, 10),
 		configEvent: make(chan struct{}, 10),
+		runtimeRoot: config.RuntimeRoot,
 	}
 	}
 
 
 	st, err := c.loadState()
 	st, err := c.loadState()
@@ -275,7 +286,7 @@ func (c *Cluster) startNewNode(forceNewCluster bool, localAddr, remoteAddr, list
 	n, err := swarmagent.NewNode(&swarmagent.NodeConfig{
 	n, err := swarmagent.NewNode(&swarmagent.NodeConfig{
 		Hostname:           c.config.Name,
 		Hostname:           c.config.Name,
 		ForceNewCluster:    forceNewCluster,
 		ForceNewCluster:    forceNewCluster,
-		ListenControlAPI:   filepath.Join(c.root, controlSocket),
+		ListenControlAPI:   filepath.Join(c.runtimeRoot, controlSocket),
 		ListenRemoteAPI:    listenAddr,
 		ListenRemoteAPI:    listenAddr,
 		AdvertiseRemoteAPI: advertiseAddr,
 		AdvertiseRemoteAPI: advertiseAddr,
 		JoinAddr:           joinAddr,
 		JoinAddr:           joinAddr,

+ 3 - 1
integration-cli/daemon.go

@@ -41,6 +41,7 @@ type Daemon struct {
 	userlandProxy     bool
 	userlandProxy     bool
 	useDefaultHost    bool
 	useDefaultHost    bool
 	useDefaultTLSHost bool
 	useDefaultTLSHost bool
+	execRoot          string
 }
 }
 
 
 type clientConfig struct {
 type clientConfig struct {
@@ -81,6 +82,7 @@ func NewDaemon(c *check.C) *Daemon {
 		root:          daemonRoot,
 		root:          daemonRoot,
 		storageDriver: os.Getenv("DOCKER_GRAPHDRIVER"),
 		storageDriver: os.Getenv("DOCKER_GRAPHDRIVER"),
 		userlandProxy: userlandProxy,
 		userlandProxy: userlandProxy,
+		execRoot:      filepath.Join(os.TempDir(), "docker-execroot", id),
 	}
 	}
 }
 }
 
 
@@ -145,7 +147,7 @@ func (d *Daemon) StartWithLogFile(out *os.File, providedArgs ...string) error {
 	args := append(d.GlobalFlags,
 	args := append(d.GlobalFlags,
 		"--containerd", "/var/run/docker/libcontainerd/docker-containerd.sock",
 		"--containerd", "/var/run/docker/libcontainerd/docker-containerd.sock",
 		"--graph", d.root,
 		"--graph", d.root,
-		"--exec-root", filepath.Join(d.folder, "exec-root"),
+		"--exec-root", d.execRoot,
 		"--pidfile", fmt.Sprintf("%s/docker.pid", d.folder),
 		"--pidfile", fmt.Sprintf("%s/docker.pid", d.folder),
 		fmt.Sprintf("--userland-proxy=%t", d.userlandProxy),
 		fmt.Sprintf("--userland-proxy=%t", d.userlandProxy),
 	)
 	)