mirror of
https://github.com/kemko/nomad.git
synced 2026-01-05 18:05:42 +03:00
Docker Volume Drivers
This commit adds the functionality to use Docker Volume Drivers.
This commit is contained in:
@@ -154,6 +154,7 @@ type DockerDriverConfig struct {
|
||||
WorkDir string `mapstructure:"work_dir"` // Working directory inside the container
|
||||
Logging []DockerLoggingOpts `mapstructure:"logging"` // Logging options for syslog server
|
||||
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
|
||||
}
|
||||
|
||||
@@ -191,6 +192,7 @@ func NewDockerDriverConfig(task *structs.Task, env *env.TaskEnvironment) (*Docke
|
||||
dconf.Hostname = env.ReplaceEnv(dconf.Hostname)
|
||||
dconf.WorkDir = env.ReplaceEnv(dconf.WorkDir)
|
||||
dconf.Volumes = env.ParseAndReplace(dconf.Volumes)
|
||||
dconf.VolumeDriver = env.ReplaceEnv(dconf.VolumeDriver)
|
||||
dconf.DNSServers = env.ParseAndReplace(dconf.DNSServers)
|
||||
dconf.DNSSearchDomains = env.ParseAndReplace(dconf.DNSSearchDomains)
|
||||
dconf.LoadImages = env.ParseAndReplace(dconf.LoadImages)
|
||||
@@ -388,6 +390,9 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error {
|
||||
"volumes": &fields.FieldSchema{
|
||||
Type: fields.TypeArray,
|
||||
},
|
||||
"volume_driver": &fields.FieldSchema{
|
||||
Type: fields.TypeString,
|
||||
},
|
||||
"force_pull": &fields.FieldSchema{
|
||||
Type: fields.TypeBool,
|
||||
},
|
||||
@@ -695,8 +700,13 @@ func (d *DockerDriver) containerBinds(driverConfig *DockerDriverConfig, taskDir
|
||||
}
|
||||
|
||||
// Relative paths are always allowed as they mount within a container
|
||||
// Expand path relative to alloc dir
|
||||
parts[0] = filepath.Join(taskDir.Dir, parts[0])
|
||||
// When a VolumeDriver is set, we assume we receive a binding in the format volume-name:container-dest
|
||||
// Otherwise, we assume we receive a relative path binding in the format relative/to/task:/also/in/container
|
||||
if driverConfig.VolumeDriver == "" {
|
||||
// Expand path relative to alloc dir
|
||||
parts[0] = filepath.Join(taskDir.Dir, parts[0])
|
||||
}
|
||||
|
||||
binds = append(binds, strings.Join(parts, ":"))
|
||||
}
|
||||
|
||||
@@ -761,6 +771,8 @@ func (d *DockerDriver) createContainerConfig(ctx *ExecContext, task *structs.Tas
|
||||
// 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,
|
||||
|
||||
VolumeDriver: driverConfig.VolumeDriver,
|
||||
}
|
||||
|
||||
// Windows does not support MemorySwap #2193
|
||||
|
||||
@@ -201,6 +201,26 @@ The `docker` driver supports the following configuration in the job spec:
|
||||
]
|
||||
}
|
||||
```
|
||||
* `volume_driver` - (Optional) The name of the volume driver used to mount
|
||||
volumes. Must be used along with `volumes`.
|
||||
Using a `volume_driver` also allows to use `volumes` with a named volume as
|
||||
well as regular paths.
|
||||
|
||||
```hcl
|
||||
config {
|
||||
volumes = [
|
||||
# Use absolute paths to mount arbitrary paths on the host
|
||||
"/path/on/host:/path/in/container",
|
||||
|
||||
# Use relative paths to rebind paths already in the allocation dir
|
||||
"relative/to/task:/also/in/container",
|
||||
|
||||
# Use named volume created outside nomad.
|
||||
"name-of-the-volume:/path/in/container"
|
||||
]
|
||||
volume_driver = "flocker"
|
||||
}
|
||||
```
|
||||
|
||||
* `work_dir` - (Optional) The working directory inside the container.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user