Merge pull request #1806 from hashicorp/f-docker4mac-fixes

A couple fixes to make Docker For Mac work
This commit is contained in:
Alex Dadgar 2016-10-27 09:29:40 -07:00 committed by GitHub
commit 150b678a6b
4 changed files with 51 additions and 10 deletions

View file

@ -287,6 +287,12 @@ func (c *Client) init() error {
if err != nil { if err != nil {
return fmt.Errorf("failed creating temporary directory for the StateDir: %v", err) 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.config.StateDir = p
} }
c.logger.Printf("[INFO] client: using state directory %v", c.config.StateDir) c.logger.Printf("[INFO] client: using state directory %v", c.config.StateDir)
@ -302,6 +308,12 @@ func (c *Client) init() error {
if err != nil { if err != nil {
return fmt.Errorf("failed creating temporary directory for the AllocDir: %v", err) 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 c.config.AllocDir = p
} }

View file

@ -476,13 +476,15 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task,
memLimit := int64(task.Resources.MemoryMB) * 1024 * 1024 memLimit := int64(task.Resources.MemoryMB) * 1024 * 1024
if len(driverConfig.Logging) == 0 { if len(driverConfig.Logging) == 0 {
d.logger.Printf("[DEBUG] driver.docker: Setting default logging options to syslog and %s", syslogAddr) if runtime.GOOS != "darwin" {
driverConfig.Logging = []DockerLoggingOpts{ d.logger.Printf("[DEBUG] driver.docker: Setting default logging options to syslog and %s", syslogAddr)
{Type: "syslog", Config: map[string]string{"syslog-address": 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{ hostConfig := &docker.HostConfig{
// Convert MB to bytes. This is an absolute value. // 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 // local directory for storage and a shared alloc directory that can be
// used to share data between different tasks in the same task group. // used to share data between different tasks in the same task group.
Binds: binds, 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, Type: driverConfig.Logging[0].Type,
Config: driverConfig.Logging[0].Config, Config: driverConfig.Logging[0].Config,
}, }
} }
d.logger.Printf("[DEBUG] driver.docker: using %d bytes memory for %s", hostConfig.Memory, task.Name) 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! // Only launch syslog server if we're going to use it!
syslogAddr := "" 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() ss, err := exec.LaunchSyslogServer()
if err != nil { if err != nil {
pluginClient.Kill() pluginClient.Kill()

View file

@ -457,8 +457,14 @@ func (e *UniversalExecutor) Exit() error {
if e.syslogServer != nil { if e.syslogServer != nil {
e.syslogServer.Shutdown() 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 { if e.consulSyncer != nil {
e.consulSyncer.Shutdown() e.consulSyncer.Shutdown()

View file

@ -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 need a higher degree of isolation between processes for security or other
reasons, it is recommended to use full virtualization like reasons, it is recommended to use full virtualization like
[QEMU](/docs/drivers/qemu.html). [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.