Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A couple fixes to make Docker For Mac work #1806

Merged
merged 5 commits into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,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 @@ -290,6 +296,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 @@ -449,13 +449,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 @@ -468,10 +470,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 @@ -790,7 +796,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 @@ -452,8 +452,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 @@ -454,3 +454,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.