2015-04-27 12:25:38 -04:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
2015-06-03 12:26:41 -04:00
|
|
|
import (
|
2015-11-03 14:25:22 -05:00
|
|
|
"sort"
|
|
|
|
|
2015-11-12 14:55:17 -05:00
|
|
|
"github.com/docker/docker/container"
|
2015-09-09 22:23:06 -04:00
|
|
|
"github.com/docker/docker/volume"
|
2015-06-03 12:26:41 -04:00
|
|
|
)
|
2015-05-19 16:05:25 -04:00
|
|
|
|
2015-09-09 22:23:06 -04:00
|
|
|
// setupMounts configures the mount points for a container by appending each
|
2016-03-18 15:43:17 -04:00
|
|
|
// of the configured mounts on the container to the OCI mount structure
|
|
|
|
// which will ultimately be passed into the oci runtime during container creation.
|
2015-09-09 22:23:06 -04:00
|
|
|
// It also ensures each of the mounts are lexographically sorted.
|
2016-03-18 14:53:27 -04:00
|
|
|
|
|
|
|
// BUGBUG TODO Windows containerd. This would be much better if it returned
|
2016-09-27 13:26:59 -04:00
|
|
|
// an array of runtime spec mounts, not container mounts. Then no need to
|
2016-03-18 14:53:27 -04:00
|
|
|
// do multiple transitions.
|
|
|
|
|
|
|
|
func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, error) {
|
|
|
|
var mnts []container.Mount
|
|
|
|
for _, mount := range c.MountPoints { // type is volume.MountPoint
|
|
|
|
if err := daemon.lazyInitializeVolume(c.ID, mount); err != nil {
|
2016-01-12 17:18:57 -05:00
|
|
|
return nil, err
|
2015-12-09 14:39:31 -05:00
|
|
|
}
|
2016-09-19 16:57:55 -04:00
|
|
|
s, err := mount.Setup(c.MountLabel, 0, 0)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-09-09 22:23:06 -04:00
|
|
|
}
|
2016-09-19 16:57:55 -04:00
|
|
|
|
2016-03-18 14:53:27 -04:00
|
|
|
mnts = append(mnts, container.Mount{
|
2015-09-09 22:23:06 -04:00
|
|
|
Source: s,
|
|
|
|
Destination: mount.Destination,
|
|
|
|
Writable: mount.RW,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Sort(mounts(mnts))
|
|
|
|
return mnts, nil
|
2015-04-29 18:53:35 -04:00
|
|
|
}
|
2015-06-08 16:45:28 -04:00
|
|
|
|
2015-09-09 22:23:06 -04:00
|
|
|
// setBindModeIfNull is platform specific processing which is a no-op on
|
|
|
|
// Windows.
|
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 14:25:35 -04:00
|
|
|
func setBindModeIfNull(bind *volume.MountPoint) {
|
|
|
|
return
|
2015-09-09 22:23:06 -04:00
|
|
|
}
|