Skip to content

Commit

Permalink
Service registration for IPv6 docker addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
42wim committed Jan 24, 2018
1 parent bc5d5ed commit 0df2e61
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
7 changes: 7 additions & 0 deletions client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ type DockerDriverConfig struct {
Devices []DockerDevice `mapstructure:"devices"` // To allow mounting USB or other serial control devices
CapAdd []string `mapstructure:"cap_add"` // Flags to pass directly to cap-add
CapDrop []string `mapstructure:"cap_drop"` // Flags to pass directly to cap-drop
UseIPv6Address bool `mapstructure:"use_ipv6_address"` // Flag to use the GlobalIPv6Address from the container as the detected IP
}

func sliceMergeUlimit(ulimitsRaw map[string]string) ([]docker.ULimit, error) {
Expand Down Expand Up @@ -670,6 +671,9 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error {
"cap_drop": {
Type: fields.TypeArray,
},
"use_ipv6_address": {
Type: fields.TypeBool,
},
},
}

Expand Down Expand Up @@ -880,6 +884,9 @@ func (d *DockerDriver) detectIP(c *docker.Container) (string, bool) {
}

ip = net.IPAddress
if d.driverConfig.UseIPv6Address {
ip = net.GlobalIPv6Address
}
ipName = name

// Don't auto-advertise IPs for default networks (bridge on
Expand Down
5 changes: 5 additions & 0 deletions website/source/docs/drivers/docker.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ The `docker` driver supports the following configuration in the job spec. Only
]
}
```
* `use_ipv6_address` - (Optional) `true` or `false` (default). Use IPv6 Address
will use the containers IPv6 address (GlobalIPv6Address) when registering service checks and using
`address_mode = driver`.
See [service](/docs/job-specification/service.html) for details.


### Container Name

Expand Down
70 changes: 70 additions & 0 deletions website/source/docs/job-specification/service.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ does not automatically enable service discovery.
`address_mode="driver"`. Numeric ports may be used when in driver addressing
mode.

Docker and IPv6 containers: This setting is required if you want to register
the port of the (IPv6) service. See [below for examples.](#IPv6 docker containers)

- `tags` `(array<string>: [])` - Specifies the list of tags to associate with
this service. If this is not supplied, no tags will be assigned to the service
when it is registered.
Expand All @@ -124,6 +127,10 @@ does not automatically enable service discovery.
addresses. Task will fail if driver network cannot be determined. Only
implemented for Docker and rkt.

Docker and IPv6 containers: If you want to register the IPv6 address
of the container you'll have to enable this and specify `use_ipv6_address`
in the docker driver configuration. See [below for examples.](#IPv6 docker containers)

- `host` - Use the host IP and port.

### `check` Parameters
Expand All @@ -140,6 +147,10 @@ scripts.
[below for details.](#using-driver-address-mode) Unlike `port`, this setting
is *not* inherited from the `service`.

Docker and IPv6 containers: If you want to check the IPv6 address
of the container you'll have to enable this and specify `use_ipv6_address`
in the docker driver configuration. See [below for examples.](#IPv6 docker containers)

- `args` `(array<string>: [])` - Specifies additional arguments to the
`command`. This only applies to script-based health checks.

Expand Down Expand Up @@ -186,6 +197,9 @@ scripts.
default. In Nomad 0.7.1 or later numeric ports may be used if
`address_mode="driver"` is set on the check.

Docker and IPv6 containers: Using a numeric port is required if you want to
check the port of (IPv6) service. See [below for examples.](#IPv6 docker containers)

- `protocol` `(string: "http")` - Specifies the protocol for the http-based
health checks. Valid options are `http` and `https`.

Expand Down Expand Up @@ -463,6 +477,62 @@ In this case Nomad doesn't need to assign Redis any host ports. The `service`
and `check` stanzas can both specify the port number to advertise and check
directly since Nomad isn't managing any port assignments.

### IPv6 docker containers

The [Docker](/docs/drivers/docker.html#use_ipv6_address) driver support the
`use_ipv6_address` parameter in it's configuration.

Besides enabling this parameter you have to set `address_mode` parameter in
both `service` and `check` stanzas to `driver`.

You also have explicily specify the `port` that will be registered and checked.

For example

```hcl
job "example" {
datacenters = ["dc1"]
group "cache" {
task "redis" {
driver = "docker"
config {
image = "redis:3.2"
use_ipv6_address = true
# No port map required!
}
resources {
cpu = 500 # 500 MHz
memory = 256 # 256MB
network {
mbits = 10
}
}
service {
name = "ipv6-redis"
port = 6379
address_mode = "driver"
check {
name = "ipv6-redis-check"
type = "tcp"
interval = "10s"
timeout = "2s"
port = 6379
address_mode = "driver"
}
}
}
}
}
```

With IPv6 Nomad doesn't need to assign Redis any host ports. The `service`
and `check` stanzas can both specify the port number to advertise and check
directly since Nomad isn't managing any port assignments.


- - -

Expand Down

0 comments on commit 0df2e61

Please sign in to comment.