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

Expanded docker driver options #390

Merged
merged 4 commits into from
Nov 6, 2015
Merged
Show file tree
Hide file tree
Changes from 2 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
37 changes: 35 additions & 2 deletions client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"log"
"net"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -166,6 +167,32 @@ func (d *DockerDriver) createContainer(ctx *ExecContext, task *structs.Task) (do
d.logger.Printf("[DEBUG] driver.docker: using %d cpu shares for %s", hostConfig.CPUShares, task.Config["image"])
d.logger.Printf("[DEBUG] driver.docker: binding directories %#v for %s", hostConfig.Binds, task.Config["image"])

// set privileged (fallback to false)
hostConfig.Privileged, _ = strconv.ParseBool(task.Config["privileged"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you handle the error here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since privileged is a potentially dangerous flag, we want to give the Nomad operator control over whether this is allowed. So what should happen is there should be a name key/value to enable or disable the docker driver from allowing the privileged flag:

That would go here: https://github.com/hashicorp/nomad/blob/master/client/config/config.go#L55
Here is an example:

_, err = strconv.ParseBool(d.config.ReadDefault("docker.cleanup.container", "true"))

And the default should be that privileged is not enabled. The docker driver should also set a node attribute to indicate if it allows privileged. Let me know if you need clarification

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes perfect sense, I'll update the PR


// set DNS servers
dns, ok := task.Config["dns-servers"]

if ok && dns != "" {
for _, v := range strings.Split(dns, ",") {
ip := strings.TrimSpace(v)
if net.ParseIP(ip) != nil {
hostConfig.DNS = append(hostConfig.DNS, ip)
} else {
d.logger.Printf("[ERR] driver.docker: invalid ip address for container dns server: %s", ip)
}
}
}

// set DNS search domains
dnsSearch, ok := task.Config["search-domains"]

if ok && dnsSearch != "" {
for _, v := range strings.Split(dnsSearch, ",") {
hostConfig.DNSSearch = append(hostConfig.DNSSearch, strings.TrimSpace(v))
}
}

mode, ok := task.Config["network_mode"]
if !ok || mode == "" {
// docker default
Expand Down Expand Up @@ -303,8 +330,14 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle
Repository: repo,
Tag: tag,
}
// TODO add auth configuration for private repos
authOptions := docker.AuthConfiguration{}

authOptions := docker.AuthConfiguration{
Username: task.Config["auth.username"],
Password: task.Config["auth.password"],
Email: task.Config["auth.email"],
ServerAddress: task.Config["auth.server-address"],
}

err = client.PullImage(pullOptions, authOptions)
if err != nil {
d.logger.Printf("[ERR] driver.docker: pulling container %s", err)
Expand Down
18 changes: 18 additions & 0 deletions website/source/docs/drivers/docker.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ The `docker` driver supports the following configuration in the job specificatio
network mode is not supported right now and is reported as an invalid
option.

* `privileged` - (optional) Privileged mode gives the container full access to
the host. Valid options are `"true"` and `"false"` (defaults to `"false"`).

* `dns-servers` - (optional) A comma separated list of DNS servers for the container
to use (e.g. "8.8.8.8,8.8.4.4"). *Docker API v1.10 and above only*

* `search-domains` - (optional) A comma separated list of DNS search domains for the
container to use.

**Authentication**
Registry authentication can be set per task with the following authentication
parameters. These options can provide access to private repositories that
utilize the docker remote api (e.g. dockerhub, quay.io)
- `auth.username` - (optional) The account username
- `auth.password` - (optional) The account password
- `auth.email` - (optional) The account email
- `auth.server-address` - (optional) The server domain/ip without the protocol

### Port Mapping

Nomad uses port binding to expose services running in containers using the port
Expand Down