mac address pinning in docker driver

This commit adds mac address pining to the docker driver.
This commit is contained in:
johannesa 2017-05-17 16:41:00 +02:00
parent 57f643b252
commit ea644237cf

View file

@ -161,6 +161,7 @@ type DockerDriverConfig struct {
Volumes []string `mapstructure:"volumes"` // Host-Volumes to mount in, syntax: /path/to/host/directory:/destination/path/in/container
VolumeDriver string `mapstructure:"volume_driver"` // Docker volume driver used for the container's volumes
ForcePull bool `mapstructure:"force_pull"` // Always force pull before running image, useful if your tags are mutable
MacAddress string `mapstructure:"mac_address"` // Pin mac address to container
}
// Validate validates a docker driver config
@ -204,6 +205,7 @@ func NewDockerDriverConfig(task *structs.Task, env *env.TaskEnvironment) (*Docke
dconf.DNSServers = env.ParseAndReplace(dconf.DNSServers)
dconf.DNSSearchDomains = env.ParseAndReplace(dconf.DNSSearchDomains)
dconf.ExtraHosts = env.ParseAndReplace(dconf.ExtraHosts)
dconf.MacAddress = env.ReplaceEnv(dconf.MacAddress)
for _, m := range dconf.LabelsRaw {
for k, v := range m {
@ -355,6 +357,9 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error {
"ipv6_address": &fields.FieldSchema{
Type: fields.TypeString,
},
"mac_address": &fields.FieldSchema{
Type: fields.TypeString,
},
"pid_mode": &fields.FieldSchema{
Type: fields.TypeString,
},
@ -953,6 +958,12 @@ func (d *DockerDriver) createContainerConfig(ctx *ExecContext, task *structs.Tas
hostConfig.NetworkMode, driverConfig.IPv4Address, driverConfig.IPv6Address)
}
if driverConfig.MacAddress != "" {
config.MacAddress = driverConfig.MacAddress
d.logger.Printf("[DEBUG] driver.docker: using pinned mac address: %q",
config.MacAddress)
}
return docker.CreateContainerOptions{
Name: containerName,
Config: config,