Skip to content

Commit

Permalink
Merge pull request #1806 from hashicorp/f-docker4mac-fixes
Browse files Browse the repository at this point in the history
A couple fixes to make Docker For Mac work
  • Loading branch information
dadgar committed Oct 27, 2016
2 parents 76fe648 + 00ce1e5 commit a186f7a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
12 changes: 12 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
24 changes: 16 additions & 8 deletions client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions client/driver/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 15 additions & 0 deletions website/source/docs/drivers/docker.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit a186f7a

Please sign in to comment.