From 5d2960034151bc38190f9ac49e5ff7de0a092aff Mon Sep 17 00:00:00 2001 From: Pietro Menna Date: Thu, 23 Feb 2017 14:36:32 -0300 Subject: [PATCH 1/2] Docker Volume Drivers This commit adds the functionality to use Docker Volume Drivers. --- client/driver/docker.go | 16 ++++++++++++++-- website/source/docs/drivers/docker.html.md | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/client/driver/docker.go b/client/driver/docker.go index 8536a6c2a53..da5a9bdfab1 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -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 diff --git a/website/source/docs/drivers/docker.html.md b/website/source/docs/drivers/docker.html.md index 5cec7569d23..38cc4f96e9c 100644 --- a/website/source/docs/drivers/docker.html.md +++ b/website/source/docs/drivers/docker.html.md @@ -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. From c57d9c6bdba29b68d7c9c993a9cda3215fcbd671 Mon Sep 17 00:00:00 2001 From: Pietro Menna Date: Thu, 23 Feb 2017 16:01:27 -0300 Subject: [PATCH 2/2] Improved documentation for Docker Volume Drivers Incorporated comments from @schmichael --- website/source/docs/drivers/docker.html.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/website/source/docs/drivers/docker.html.md b/website/source/docs/drivers/docker.html.md index 38cc4f96e9c..4dbdf1aa053 100644 --- a/website/source/docs/drivers/docker.html.md +++ b/website/source/docs/drivers/docker.html.md @@ -209,15 +209,10 @@ The `docker` driver supports the following configuration in the job spec: ```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" ] + # Name of the Docker Volume Driver used by the container volume_driver = "flocker" } ```