2018-02-05 16:05:59 -05:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2015-04-27 12:25:38 -04:00
|
|
|
|
2015-06-03 12:26:41 -04:00
|
|
|
import (
|
2015-11-03 14:25:22 -05:00
|
|
|
"sort"
|
|
|
|
|
2018-01-18 16:55:27 -05:00
|
|
|
"github.com/docker/docker/api/types/mount"
|
2015-11-12 14:55:17 -05:00
|
|
|
"github.com/docker/docker/container"
|
2017-05-19 18:06:46 -04:00
|
|
|
"github.com/docker/docker/pkg/idtools"
|
2018-04-17 16:50:28 -04:00
|
|
|
volumemounts "github.com/docker/docker/volume/mounts"
|
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.
|
2017-02-16 07:08:57 -05:00
|
|
|
// It also ensures each of the mounts are lexicographically 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
|
2018-04-17 16:50:28 -04:00
|
|
|
for _, mount := range c.MountPoints { // type is volumemounts.MountPoint
|
2016-03-18 14:53:27 -04:00
|
|
|
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
|
|
|
}
|
2018-05-17 10:29:52 -04:00
|
|
|
s, err := mount.Setup(c.MountLabel, idtools.IDPair{UID: 0, GID: 0}, nil)
|
2016-09-19 16:57:55 -04:00
|
|
|
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.
|
2018-04-17 16:50:28 -04:00
|
|
|
func setBindModeIfNull(bind *volumemounts.MountPoint) {
|
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
|
|
|
return
|
2015-09-09 22:23:06 -04:00
|
|
|
}
|
2018-01-18 16:55:27 -05:00
|
|
|
|
|
|
|
func (daemon *Daemon) validateBindDaemonRoot(m mount.Mount) (bool, error) {
|
|
|
|
return false, nil
|
|
|
|
}
|