2018-02-05 21:05:59 +00:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2014-02-15 01:15:40 +00:00
|
|
|
|
|
|
|
import (
|
2018-03-22 21:11:03 +00:00
|
|
|
"context"
|
2014-02-15 01:15:40 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2017-04-25 17:05:21 +00:00
|
|
|
"reflect"
|
2014-02-15 01:15:40 +00:00
|
|
|
"strings"
|
2017-05-17 21:19:13 +00:00
|
|
|
"time"
|
2014-05-05 21:45:14 +00:00
|
|
|
|
2016-09-06 18:18:12 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
containertypes "github.com/docker/docker/api/types/container"
|
2018-01-18 21:55:27 +00:00
|
|
|
"github.com/docker/docker/api/types/mount"
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
mounttypes "github.com/docker/docker/api/types/mount"
|
2015-11-12 19:55:17 +00:00
|
|
|
"github.com/docker/docker/container"
|
2018-01-11 19:53:06 +00:00
|
|
|
"github.com/docker/docker/errdefs"
|
2015-05-19 20:05:25 +00:00
|
|
|
"github.com/docker/docker/volume"
|
2018-04-17 20:50:28 +00:00
|
|
|
volumemounts "github.com/docker/docker/volume/mounts"
|
2018-03-22 21:11:03 +00:00
|
|
|
"github.com/docker/docker/volume/service"
|
|
|
|
volumeopts "github.com/docker/docker/volume/service/opts"
|
2017-07-19 14:20:13 +00:00
|
|
|
"github.com/pkg/errors"
|
2017-07-26 21:42:13 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2014-02-15 01:15:40 +00:00
|
|
|
)
|
|
|
|
|
2015-06-12 13:25:32 +00:00
|
|
|
var (
|
|
|
|
// ErrVolumeReadonly is used to signal an error when trying to copy data into
|
|
|
|
// a volume mount that is not writable.
|
|
|
|
ErrVolumeReadonly = errors.New("mounted volume is marked read-only")
|
|
|
|
)
|
2015-05-13 01:21:26 +00:00
|
|
|
|
2016-03-18 18:50:19 +00:00
|
|
|
type mounts []container.Mount
|
2014-12-16 15:06:45 +00:00
|
|
|
|
2015-09-10 02:23:06 +00:00
|
|
|
// Len returns the number of mounts. Used in sorting.
|
|
|
|
func (m mounts) Len() int {
|
|
|
|
return len(m)
|
|
|
|
}
|
2014-08-28 14:18:08 +00:00
|
|
|
|
2015-09-10 02:23:06 +00:00
|
|
|
// Less returns true if the number of parts (a/b/c would be 3 parts) in the
|
|
|
|
// mount indexed by parameter 1 is less than that of the mount indexed by
|
|
|
|
// parameter 2. Used in sorting.
|
|
|
|
func (m mounts) Less(i, j int) bool {
|
|
|
|
return m.parts(i) < m.parts(j)
|
2014-12-16 15:06:45 +00:00
|
|
|
}
|
|
|
|
|
2015-09-10 02:23:06 +00:00
|
|
|
// Swap swaps two items in an array of mounts. Used in sorting
|
|
|
|
func (m mounts) Swap(i, j int) {
|
|
|
|
m[i], m[j] = m[j], m[i]
|
|
|
|
}
|
2015-05-13 01:21:26 +00:00
|
|
|
|
2015-09-10 02:23:06 +00:00
|
|
|
// parts returns the number of parts in the destination of a mount. Used in sorting.
|
|
|
|
func (m mounts) parts(i int) int {
|
|
|
|
return strings.Count(filepath.Clean(m[i].Destination), string(os.PathSeparator))
|
2015-05-13 01:21:26 +00:00
|
|
|
}
|
|
|
|
|
2015-09-10 02:23:06 +00:00
|
|
|
// registerMountPoints initializes the container mount points with the configured volumes and bind mounts.
|
|
|
|
// It follows the next sequence to decide what to mount in each final destination:
|
|
|
|
//
|
|
|
|
// 1. Select the previously configured mount points for the containers, if any.
|
|
|
|
// 2. Select the volumes mounted from another containers. Overrides previously configured mount point destination.
|
|
|
|
// 3. Select the bind mounts set by the client. Overrides previously configured mount point destinations.
|
2015-12-13 16:00:39 +00:00
|
|
|
// 4. Cleanup old volumes that are about to be reassigned.
|
2016-05-07 02:48:02 +00:00
|
|
|
func (daemon *Daemon) registerMountPoints(container *container.Container, hostConfig *containertypes.HostConfig) (retErr error) {
|
2015-09-10 02:23:06 +00:00
|
|
|
binds := map[string]bool{}
|
2018-04-17 20:50:28 +00:00
|
|
|
mountPoints := map[string]*volumemounts.MountPoint{}
|
|
|
|
parser := volumemounts.NewParser(container.OS)
|
|
|
|
|
2018-03-22 21:11:03 +00:00
|
|
|
ctx := context.TODO()
|
2016-05-07 02:48:02 +00:00
|
|
|
defer func() {
|
|
|
|
// clean up the container mountpoints once return with error
|
|
|
|
if retErr != nil {
|
|
|
|
for _, m := range mountPoints {
|
|
|
|
if m.Volume == nil {
|
|
|
|
continue
|
|
|
|
}
|
2018-03-22 21:11:03 +00:00
|
|
|
daemon.volumes.Release(ctx, m.Volume.Name(), container.ID)
|
2016-05-07 02:48:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
2015-09-10 02:23:06 +00:00
|
|
|
|
2017-01-27 22:12:45 +00:00
|
|
|
dereferenceIfExists := func(destination string) {
|
|
|
|
if v, ok := mountPoints[destination]; ok {
|
|
|
|
logrus.Debugf("Duplicate mount point '%s'", destination)
|
|
|
|
if v.Volume != nil {
|
2018-03-22 21:11:03 +00:00
|
|
|
daemon.volumes.Release(ctx, v.Volume.Name(), container.ID)
|
2017-01-27 22:12:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-10 02:23:06 +00:00
|
|
|
// 1. Read already configured mount points.
|
2016-09-17 02:52:11 +00:00
|
|
|
for destination, point := range container.MountPoints {
|
|
|
|
mountPoints[destination] = point
|
2014-08-21 21:57:46 +00:00
|
|
|
}
|
|
|
|
|
2015-09-10 02:23:06 +00:00
|
|
|
// 2. Read volumes from other containers.
|
|
|
|
for _, v := range hostConfig.VolumesFrom {
|
2017-08-01 17:32:44 +00:00
|
|
|
containerID, mode, err := parser.ParseVolumesFrom(v)
|
2015-09-10 02:23:06 +00:00
|
|
|
if err != nil {
|
2020-06-29 11:28:14 +00:00
|
|
|
return errdefs.InvalidParameter(err)
|
2015-09-10 02:23:06 +00:00
|
|
|
}
|
2014-08-21 21:57:46 +00:00
|
|
|
|
2015-12-11 17:39:28 +00:00
|
|
|
c, err := daemon.GetContainer(containerID)
|
2015-09-10 02:23:06 +00:00
|
|
|
if err != nil {
|
2020-06-29 11:28:14 +00:00
|
|
|
return errdefs.InvalidParameter(err)
|
2015-09-10 02:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, m := range c.MountPoints {
|
2018-04-17 20:50:28 +00:00
|
|
|
cp := &volumemounts.MountPoint{
|
2017-04-25 17:05:21 +00:00
|
|
|
Type: m.Type,
|
2015-09-10 02:23:06 +00:00
|
|
|
Name: m.Name,
|
|
|
|
Source: m.Source,
|
2017-08-01 17:32:44 +00:00
|
|
|
RW: m.RW && parser.ReadWrite(mode),
|
2015-09-10 02:23:06 +00:00
|
|
|
Driver: m.Driver,
|
|
|
|
Destination: m.Destination,
|
2015-10-23 20:57:57 +00:00
|
|
|
Propagation: m.Propagation,
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
Spec: m.Spec,
|
|
|
|
CopyData: false,
|
2015-09-10 02:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(cp.Source) == 0 {
|
2018-03-22 21:11:03 +00:00
|
|
|
v, err := daemon.volumes.Get(ctx, cp.Name, volumeopts.WithGetDriver(cp.Driver), volumeopts.WithGetReference(container.ID))
|
2015-09-10 02:23:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-03-22 21:11:03 +00:00
|
|
|
cp.Volume = &volumeWrapper{v: v, s: daemon.volumes}
|
2015-09-10 02:23:06 +00:00
|
|
|
}
|
2017-01-27 22:12:45 +00:00
|
|
|
dereferenceIfExists(cp.Destination)
|
2015-09-10 02:23:06 +00:00
|
|
|
mountPoints[cp.Destination] = cp
|
|
|
|
}
|
2014-05-19 22:18:37 +00:00
|
|
|
}
|
2015-09-10 02:23:06 +00:00
|
|
|
|
|
|
|
// 3. Read bind mounts
|
|
|
|
for _, b := range hostConfig.Binds {
|
2017-08-01 17:32:44 +00:00
|
|
|
bind, err := parser.ParseMountRaw(b, hostConfig.VolumeDriver)
|
2014-05-19 22:04:51 +00:00
|
|
|
if err != nil {
|
2014-03-18 22:28:40 +00:00
|
|
|
return err
|
2014-02-15 01:15:40 +00:00
|
|
|
}
|
2018-01-18 21:55:27 +00:00
|
|
|
needsSlavePropagation, err := daemon.validateBindDaemonRoot(bind.Spec)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if needsSlavePropagation {
|
|
|
|
bind.Propagation = mount.PropagationRSlave
|
|
|
|
}
|
2015-09-10 02:23:06 +00:00
|
|
|
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
// #10618
|
2016-06-06 09:57:11 +00:00
|
|
|
_, tmpfsExists := hostConfig.Tmpfs[bind.Destination]
|
|
|
|
if binds[bind.Destination] || tmpfsExists {
|
2017-07-19 14:20:13 +00:00
|
|
|
return duplicateMountPointError(bind.Destination)
|
2015-09-10 02:23:06 +00:00
|
|
|
}
|
|
|
|
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
if bind.Type == mounttypes.TypeVolume {
|
2015-09-10 02:23:06 +00:00
|
|
|
// create the volume
|
2018-03-22 21:11:03 +00:00
|
|
|
v, err := daemon.volumes.Create(ctx, bind.Name, bind.Driver, volumeopts.WithCreateReference(container.ID))
|
2015-09-10 02:23:06 +00:00
|
|
|
if err != nil {
|
2014-02-15 01:15:40 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-03-22 21:11:03 +00:00
|
|
|
bind.Volume = &volumeWrapper{v: v, s: daemon.volumes}
|
|
|
|
bind.Source = v.Mountpoint
|
2015-09-10 02:23:06 +00:00
|
|
|
// bind.Name is an already existing volume, we need to use that here
|
2018-03-22 21:11:03 +00:00
|
|
|
bind.Driver = v.Driver
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
if bind.Driver == volume.DefaultDriverName {
|
|
|
|
setBindModeIfNull(bind)
|
2016-02-02 14:02:37 +00:00
|
|
|
}
|
2015-09-10 02:23:06 +00:00
|
|
|
}
|
2016-03-15 03:31:42 +00:00
|
|
|
|
2015-09-10 02:23:06 +00:00
|
|
|
binds[bind.Destination] = true
|
2017-01-27 22:12:45 +00:00
|
|
|
dereferenceIfExists(bind.Destination)
|
2015-09-10 02:23:06 +00:00
|
|
|
mountPoints[bind.Destination] = bind
|
2014-05-19 22:18:37 +00:00
|
|
|
}
|
2015-06-12 13:25:32 +00:00
|
|
|
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
for _, cfg := range hostConfig.Mounts {
|
2017-08-01 17:32:44 +00:00
|
|
|
mp, err := parser.ParseMountSpec(cfg)
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
if err != nil {
|
2017-11-29 04:09:37 +00:00
|
|
|
return errdefs.InvalidParameter(err)
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
}
|
2018-01-18 21:55:27 +00:00
|
|
|
needsSlavePropagation, err := daemon.validateBindDaemonRoot(mp.Spec)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if needsSlavePropagation {
|
|
|
|
mp.Propagation = mount.PropagationRSlave
|
|
|
|
}
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
|
|
|
|
if binds[mp.Destination] {
|
2017-07-19 14:20:13 +00:00
|
|
|
return duplicateMountPointError(cfg.Target)
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if mp.Type == mounttypes.TypeVolume {
|
2018-03-22 21:11:03 +00:00
|
|
|
var v *types.Volume
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
if cfg.VolumeOptions != nil {
|
|
|
|
var driverOpts map[string]string
|
|
|
|
if cfg.VolumeOptions.DriverConfig != nil {
|
|
|
|
driverOpts = cfg.VolumeOptions.DriverConfig.Options
|
|
|
|
}
|
2018-03-22 21:11:03 +00:00
|
|
|
v, err = daemon.volumes.Create(ctx,
|
|
|
|
mp.Name,
|
|
|
|
mp.Driver,
|
|
|
|
volumeopts.WithCreateReference(container.ID),
|
|
|
|
volumeopts.WithCreateOptions(driverOpts),
|
|
|
|
volumeopts.WithCreateLabels(cfg.VolumeOptions.Labels),
|
|
|
|
)
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
} else {
|
2018-03-22 21:11:03 +00:00
|
|
|
v, err = daemon.volumes.Create(ctx, mp.Name, mp.Driver, volumeopts.WithCreateReference(container.ID))
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-03-22 21:11:03 +00:00
|
|
|
mp.Volume = &volumeWrapper{v: v, s: daemon.volumes}
|
|
|
|
mp.Name = v.Name
|
|
|
|
mp.Driver = v.Driver
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
|
2018-08-30 22:32:14 +00:00
|
|
|
// need to selinux-relabel local mounts
|
|
|
|
mp.Source = v.Mountpoint
|
2017-08-30 17:10:15 +00:00
|
|
|
if mp.Driver == volume.DefaultDriverName {
|
|
|
|
setBindModeIfNull(mp)
|
|
|
|
}
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
}
|
|
|
|
|
2018-07-02 19:02:54 +00:00
|
|
|
if mp.Type == mounttypes.TypeBind {
|
|
|
|
mp.SkipMountpointCreation = true
|
|
|
|
}
|
|
|
|
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
binds[mp.Destination] = true
|
2017-01-27 22:12:45 +00:00
|
|
|
dereferenceIfExists(mp.Destination)
|
Add new `HostConfig` field, `Mounts`.
`Mounts` allows users to specify in a much safer way the volumes they
want to use in the container.
This replaces `Binds` and `Volumes`, which both still exist, but
`Mounts` and `Binds`/`Volumes` are exclussive.
The CLI will continue to use `Binds` and `Volumes` due to concerns with
parsing the volume specs on the client side and cross-platform support
(for now).
The new API follows exactly the services mount API.
Example usage of `Mounts`:
```
$ curl -XPOST localhost:2375/containers/create -d '{
"Image": "alpine:latest",
"HostConfig": {
"Mounts": [{
"Type": "Volume",
"Target": "/foo"
},{
"Type": "bind",
"Source": "/var/run/docker.sock",
"Target": "/var/run/docker.sock",
},{
"Type": "volume",
"Name": "important_data",
"Target": "/var/data",
"ReadOnly": true,
"VolumeOptions": {
"DriverConfig": {
Name: "awesomeStorage",
Options: {"size": "10m"},
Labels: {"some":"label"}
}
}]
}
}'
```
There are currently 2 types of mounts:
- **bind**: Paths on the host that get mounted into the
container. Paths must exist prior to creating the container.
- **volume**: Volumes that persist after the
container is removed.
Not all fields are available in each type, and validation is done to
ensure these fields aren't mixed up between types.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-04-26 18:25:35 +00:00
|
|
|
mountPoints[mp.Destination] = mp
|
|
|
|
}
|
|
|
|
|
2015-09-10 02:23:06 +00:00
|
|
|
container.Lock()
|
2015-11-18 10:04:23 +00:00
|
|
|
|
2015-12-13 16:00:39 +00:00
|
|
|
// 4. Cleanup old volumes that are about to be reassigned.
|
2015-11-18 10:04:23 +00:00
|
|
|
for _, m := range mountPoints {
|
2017-08-01 17:32:44 +00:00
|
|
|
if parser.IsBackwardCompatible(m) {
|
2015-11-18 10:04:23 +00:00
|
|
|
if mp, exists := container.MountPoints[m.Destination]; exists && mp.Volume != nil {
|
2018-03-22 21:11:03 +00:00
|
|
|
daemon.volumes.Release(ctx, mp.Volume.Name(), container.ID)
|
2015-11-18 10:04:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-10 02:23:06 +00:00
|
|
|
container.MountPoints = mountPoints
|
|
|
|
|
|
|
|
container.Unlock()
|
|
|
|
|
|
|
|
return nil
|
2015-06-12 13:25:32 +00:00
|
|
|
}
|
2016-01-12 22:18:57 +00:00
|
|
|
|
|
|
|
// lazyInitializeVolume initializes a mountpoint's volume if needed.
|
|
|
|
// This happens after a daemon restart.
|
2018-04-17 20:50:28 +00:00
|
|
|
func (daemon *Daemon) lazyInitializeVolume(containerID string, m *volumemounts.MountPoint) error {
|
2016-01-12 22:18:57 +00:00
|
|
|
if len(m.Driver) > 0 && m.Volume == nil {
|
2018-03-22 21:11:03 +00:00
|
|
|
v, err := daemon.volumes.Get(context.TODO(), m.Name, volumeopts.WithGetDriver(m.Driver), volumeopts.WithGetReference(containerID))
|
2016-01-12 22:18:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-03-22 21:11:03 +00:00
|
|
|
m.Volume = &volumeWrapper{v: v, s: daemon.volumes}
|
2016-01-12 22:18:57 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2016-08-04 19:34:52 +00:00
|
|
|
|
2017-04-25 17:05:21 +00:00
|
|
|
// backportMountSpec resolves mount specs (introduced in 1.13) from pre-1.13
|
|
|
|
// mount configurations
|
|
|
|
// The container lock should not be held when calling this function.
|
|
|
|
// Changes are only made in-memory and may make changes to containers referenced
|
|
|
|
// by `container.HostConfig.VolumesFrom`
|
|
|
|
func (daemon *Daemon) backportMountSpec(container *container.Container) {
|
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
|
|
|
|
2018-04-17 20:50:28 +00:00
|
|
|
parser := volumemounts.NewParser(container.OS)
|
2017-08-01 17:32:44 +00:00
|
|
|
|
2017-04-25 17:05:21 +00:00
|
|
|
maybeUpdate := make(map[string]bool)
|
|
|
|
for _, mp := range container.MountPoints {
|
|
|
|
if mp.Spec.Source != "" && mp.Type != "" {
|
|
|
|
continue
|
2016-08-04 19:34:52 +00:00
|
|
|
}
|
2017-04-25 17:05:21 +00:00
|
|
|
maybeUpdate[mp.Destination] = true
|
|
|
|
}
|
|
|
|
if len(maybeUpdate) == 0 {
|
|
|
|
return
|
|
|
|
}
|
2016-08-04 19:34:52 +00:00
|
|
|
|
2017-04-25 17:05:21 +00:00
|
|
|
mountSpecs := make(map[string]bool, len(container.HostConfig.Mounts))
|
|
|
|
for _, m := range container.HostConfig.Mounts {
|
|
|
|
mountSpecs[m.Target] = true
|
|
|
|
}
|
|
|
|
|
2018-04-17 20:50:28 +00:00
|
|
|
binds := make(map[string]*volumemounts.MountPoint, len(container.HostConfig.Binds))
|
2017-04-25 17:05:21 +00:00
|
|
|
for _, rawSpec := range container.HostConfig.Binds {
|
2017-08-01 17:32:44 +00:00
|
|
|
mp, err := parser.ParseMountRaw(rawSpec, container.HostConfig.VolumeDriver)
|
2017-04-25 17:05:21 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.WithError(err).Error("Got unexpected error while re-parsing raw volume spec during spec backport")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
binds[mp.Destination] = mp
|
|
|
|
}
|
|
|
|
|
2018-04-17 20:50:28 +00:00
|
|
|
volumesFrom := make(map[string]volumemounts.MountPoint)
|
2017-04-25 17:05:21 +00:00
|
|
|
for _, fromSpec := range container.HostConfig.VolumesFrom {
|
2017-08-01 17:32:44 +00:00
|
|
|
from, _, err := parser.ParseVolumesFrom(fromSpec)
|
2017-04-25 17:05:21 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.WithError(err).WithField("id", container.ID).Error("Error reading volumes-from spec during mount spec backport")
|
2017-05-15 19:49:07 +00:00
|
|
|
continue
|
2017-04-25 17:05:21 +00:00
|
|
|
}
|
|
|
|
fromC, err := daemon.GetContainer(from)
|
|
|
|
if err != nil {
|
|
|
|
logrus.WithError(err).WithField("from-container", from).Error("Error looking up volumes-from container")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure from container's specs have been backported
|
|
|
|
daemon.backportMountSpec(fromC)
|
|
|
|
|
|
|
|
fromC.Lock()
|
|
|
|
for t, mp := range fromC.MountPoints {
|
|
|
|
volumesFrom[t] = *mp
|
|
|
|
}
|
|
|
|
fromC.Unlock()
|
|
|
|
}
|
|
|
|
|
2018-04-17 20:50:28 +00:00
|
|
|
needsUpdate := func(containerMount, other *volumemounts.MountPoint) bool {
|
2017-04-25 17:05:21 +00:00
|
|
|
if containerMount.Type != other.Type || !reflect.DeepEqual(containerMount.Spec, other.Spec) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// main
|
|
|
|
for _, cm := range container.MountPoints {
|
|
|
|
if !maybeUpdate[cm.Destination] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// nothing to backport if from hostconfig.Mounts
|
|
|
|
if mountSpecs[cm.Destination] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if mp, exists := binds[cm.Destination]; exists {
|
|
|
|
if needsUpdate(cm, mp) {
|
|
|
|
cm.Spec = mp.Spec
|
|
|
|
cm.Type = mp.Type
|
2016-08-04 19:34:52 +00:00
|
|
|
}
|
2017-04-25 17:05:21 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if cm.Name != "" {
|
|
|
|
if mp, exists := volumesFrom[cm.Destination]; exists {
|
|
|
|
if needsUpdate(cm, &mp) {
|
|
|
|
cm.Spec = mp.Spec
|
|
|
|
cm.Type = mp.Type
|
2016-08-04 19:34:52 +00:00
|
|
|
}
|
2017-04-25 17:05:21 +00:00
|
|
|
continue
|
2016-08-04 19:34:52 +00:00
|
|
|
}
|
2017-04-25 17:05:21 +00:00
|
|
|
|
|
|
|
if cm.Type != "" {
|
|
|
|
// probably specified via the hostconfig.Mounts
|
|
|
|
continue
|
2016-08-04 19:34:52 +00:00
|
|
|
}
|
2017-04-25 17:05:21 +00:00
|
|
|
|
|
|
|
// anon volume
|
|
|
|
cm.Type = mounttypes.TypeVolume
|
|
|
|
cm.Spec.Type = mounttypes.TypeVolume
|
2016-08-04 19:34:52 +00:00
|
|
|
} else {
|
2017-04-25 17:05:21 +00:00
|
|
|
if cm.Type != "" {
|
|
|
|
// already updated
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
cm.Type = mounttypes.TypeBind
|
|
|
|
cm.Spec.Type = mounttypes.TypeBind
|
|
|
|
cm.Spec.Source = cm.Source
|
|
|
|
if cm.Propagation != "" {
|
|
|
|
cm.Spec.BindOptions = &mounttypes.BindOptions{
|
|
|
|
Propagation: cm.Propagation,
|
2016-08-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-25 17:05:21 +00:00
|
|
|
cm.Spec.Target = cm.Destination
|
|
|
|
cm.Spec.ReadOnly = !cm.RW
|
2016-08-04 19:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-22 21:11:03 +00:00
|
|
|
|
|
|
|
// VolumesService is used to perform volume operations
|
|
|
|
func (daemon *Daemon) VolumesService() *service.VolumesService {
|
|
|
|
return daemon.volumes
|
|
|
|
}
|
|
|
|
|
|
|
|
type volumeMounter interface {
|
|
|
|
Mount(ctx context.Context, v *types.Volume, ref string) (string, error)
|
|
|
|
Unmount(ctx context.Context, v *types.Volume, ref string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type volumeWrapper struct {
|
|
|
|
v *types.Volume
|
|
|
|
s volumeMounter
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *volumeWrapper) Name() string {
|
|
|
|
return v.v.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *volumeWrapper) DriverName() string {
|
|
|
|
return v.v.Driver
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *volumeWrapper) Path() string {
|
|
|
|
return v.v.Mountpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *volumeWrapper) Mount(ref string) (string, error) {
|
|
|
|
return v.s.Mount(context.TODO(), v.v, ref)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *volumeWrapper) Unmount(ref string) error {
|
|
|
|
return v.s.Unmount(context.TODO(), v.v, ref)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *volumeWrapper) CreatedAt() (time.Time, error) {
|
|
|
|
return time.Time{}, errors.New("not implemented")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *volumeWrapper) Status() map[string]interface{} {
|
|
|
|
return v.v.Status
|
|
|
|
}
|