diff --git a/client/client.go b/client/client.go index c9c990ddf..49b1a2432 100644 --- a/client/client.go +++ b/client/client.go @@ -287,6 +287,12 @@ func (c *Client) init() error { if err != nil { return fmt.Errorf("failed creating temporary directory for the StateDir: %v", err) } + + p, err = filepath.EvalSymlinks(p) + if err != nil { + return fmt.Errorf("failed to find temporary directory for the StateDir: %v", err) + } + c.config.StateDir = p } c.logger.Printf("[INFO] client: using state directory %v", c.config.StateDir) @@ -302,6 +308,12 @@ func (c *Client) init() error { if err != nil { return fmt.Errorf("failed creating temporary directory for the AllocDir: %v", err) } + + p, err = filepath.EvalSymlinks(p) + if err != nil { + return fmt.Errorf("failed to find temporary directory for the AllocDir: %v", err) + } + c.config.AllocDir = p } diff --git a/client/driver/docker.go b/client/driver/docker.go index 723a99a00..987b740d4 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -476,13 +476,15 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task, memLimit := int64(task.Resources.MemoryMB) * 1024 * 1024 if len(driverConfig.Logging) == 0 { - d.logger.Printf("[DEBUG] driver.docker: Setting default logging options to syslog and %s", syslogAddr) - driverConfig.Logging = []DockerLoggingOpts{ - {Type: "syslog", Config: map[string]string{"syslog-address": syslogAddr}}, + if runtime.GOOS != "darwin" { + d.logger.Printf("[DEBUG] driver.docker: Setting default logging options to syslog and %s", syslogAddr) + driverConfig.Logging = []DockerLoggingOpts{ + {Type: "syslog", Config: map[string]string{"syslog-address": syslogAddr}}, + } } - } - d.logger.Printf("[DEBUG] driver.docker: Using config for logging: %+v", driverConfig.Logging[0]) + d.logger.Printf("[DEBUG] driver.docker: deferring logging to docker on Docker for Mac") + } hostConfig := &docker.HostConfig{ // Convert MB to bytes. This is an absolute value. @@ -495,10 +497,14 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task, // local directory for storage and a shared alloc directory that can be // used to share data between different tasks in the same task group. Binds: binds, - LogConfig: docker.LogConfig{ + } + + if len(driverConfig.Logging) != 0 { + d.logger.Printf("[DEBUG] driver.docker: Using config for logging: %+v", driverConfig.Logging[0]) + hostConfig.LogConfig = docker.LogConfig{ Type: driverConfig.Logging[0].Type, Config: driverConfig.Logging[0].Config, - }, + } } d.logger.Printf("[DEBUG] driver.docker: using %d bytes memory for %s", hostConfig.Memory, task.Name) @@ -817,7 +823,9 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle // Only launch syslog server if we're going to use it! syslogAddr := "" - if len(driverConfig.Logging) == 0 || driverConfig.Logging[0].Type == "syslog" { + if runtime.GOOS == "darwin" && len(driverConfig.Logging) == 0 { + d.logger.Printf("[DEBUG] driver.docker: disabling syslog driver as Docker for Mac workaround") + } else if len(driverConfig.Logging) == 0 || driverConfig.Logging[0].Type == "syslog" { ss, err := exec.LaunchSyslogServer() if err != nil { pluginClient.Kill() diff --git a/client/driver/executor/executor.go b/client/driver/executor/executor.go index 372d30155..f17122e45 100644 --- a/client/driver/executor/executor.go +++ b/client/driver/executor/executor.go @@ -457,8 +457,14 @@ func (e *UniversalExecutor) Exit() error { if e.syslogServer != nil { e.syslogServer.Shutdown() } - e.lre.Close() - e.lro.Close() + + if e.lre != nil { + e.lre.Close() + } + + if e.lro != nil { + e.lro.Close() + } if e.consulSyncer != nil { e.consulSyncer.Shutdown() diff --git a/website/source/docs/drivers/docker.html.md b/website/source/docs/drivers/docker.html.md index 2372cb4ea..6acc04edb 100644 --- a/website/source/docs/drivers/docker.html.md +++ b/website/source/docs/drivers/docker.html.md @@ -461,3 +461,18 @@ Containers essentially have a virtual file system all to themselves. If you need a higher degree of isolation between processes for security or other reasons, it is recommended to use full virtualization like [QEMU](/docs/drivers/qemu.html). + +## Docker For Mac Caveats + +Docker For Mac runs docker inside a small VM and then allows access to parts of +the host filesystem into that VM. At present, nomad uses a syslog server bound to +a unix socket within a path that both the host and the VM can access to forward +log messages back to nomad. But at present, Docker For Mac does not work for +unix domain sockets (https://github.com/docker/for-mac/issues/483) in one of +these shared paths. + +As a result, using nomad with the docker driver on OS X/macOS will work, but no +logs will be available to nomad. Users must use the native docker facilities to +examine the logs of any jobs running under docker. + +In the future, we will resolve this issue, one way or another.