Skip to content

Commit 6d1b372

Browse files
authored
Merge pull request #2351 from pietromenna/docker-volume-drivers
Docker Volume Drivers
2 parents 863d9f7 + c57d9c6 commit 6d1b372

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

client/driver/docker.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ type DockerDriverConfig struct {
154154
WorkDir string `mapstructure:"work_dir"` // Working directory inside the container
155155
Logging []DockerLoggingOpts `mapstructure:"logging"` // Logging options for syslog server
156156
Volumes []string `mapstructure:"volumes"` // Host-Volumes to mount in, syntax: /path/to/host/directory:/destination/path/in/container
157+
VolumeDriver string `mapstructure:"volume_driver"` // Docker volume driver used for the container's volumes
157158
ForcePull bool `mapstructure:"force_pull"` // Always force pull before running image, useful if your tags are mutable
158159
}
159160

@@ -191,6 +192,7 @@ func NewDockerDriverConfig(task *structs.Task, env *env.TaskEnvironment) (*Docke
191192
dconf.Hostname = env.ReplaceEnv(dconf.Hostname)
192193
dconf.WorkDir = env.ReplaceEnv(dconf.WorkDir)
193194
dconf.Volumes = env.ParseAndReplace(dconf.Volumes)
195+
dconf.VolumeDriver = env.ReplaceEnv(dconf.VolumeDriver)
194196
dconf.DNSServers = env.ParseAndReplace(dconf.DNSServers)
195197
dconf.DNSSearchDomains = env.ParseAndReplace(dconf.DNSSearchDomains)
196198
dconf.LoadImages = env.ParseAndReplace(dconf.LoadImages)
@@ -388,6 +390,9 @@ func (d *DockerDriver) Validate(config map[string]interface{}) error {
388390
"volumes": &fields.FieldSchema{
389391
Type: fields.TypeArray,
390392
},
393+
"volume_driver": &fields.FieldSchema{
394+
Type: fields.TypeString,
395+
},
391396
"force_pull": &fields.FieldSchema{
392397
Type: fields.TypeBool,
393398
},
@@ -695,8 +700,13 @@ func (d *DockerDriver) containerBinds(driverConfig *DockerDriverConfig, taskDir
695700
}
696701

697702
// Relative paths are always allowed as they mount within a container
698-
// Expand path relative to alloc dir
699-
parts[0] = filepath.Join(taskDir.Dir, parts[0])
703+
// When a VolumeDriver is set, we assume we receive a binding in the format volume-name:container-dest
704+
// Otherwise, we assume we receive a relative path binding in the format relative/to/task:/also/in/container
705+
if driverConfig.VolumeDriver == "" {
706+
// Expand path relative to alloc dir
707+
parts[0] = filepath.Join(taskDir.Dir, parts[0])
708+
}
709+
700710
binds = append(binds, strings.Join(parts, ":"))
701711
}
702712

@@ -761,6 +771,8 @@ func (d *DockerDriver) createContainerConfig(ctx *ExecContext, task *structs.Tas
761771
// local directory for storage and a shared alloc directory that can be
762772
// used to share data between different tasks in the same task group.
763773
Binds: binds,
774+
775+
VolumeDriver: driverConfig.VolumeDriver,
764776
}
765777

766778
// Windows does not support MemorySwap #2193

website/source/docs/drivers/docker.html.md

+15
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,21 @@ The `docker` driver supports the following configuration in the job spec:
201201
]
202202
}
203203
```
204+
* `volume_driver` - (Optional) The name of the volume driver used to mount
205+
volumes. Must be used along with `volumes`.
206+
Using a `volume_driver` also allows to use `volumes` with a named volume as
207+
well as regular paths.
208+
209+
```hcl
210+
config {
211+
volumes = [
212+
# Use named volume created outside nomad.
213+
"name-of-the-volume:/path/in/container"
214+
]
215+
# Name of the Docker Volume Driver used by the container
216+
volume_driver = "flocker"
217+
}
218+
```
204219
205220
* `work_dir` - (Optional) The working directory inside the container.
206221

0 commit comments

Comments
 (0)