2018-02-05 21:05:59 +00:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2015-04-27 16:25:38 +00:00
|
|
|
|
2015-06-03 16:26:41 +00:00
|
|
|
import (
|
2015-11-03 19:25:22 +00:00
|
|
|
"sort"
|
|
|
|
|
2018-01-18 21:55:27 +00:00
|
|
|
"github.com/docker/docker/api/types/mount"
|
2015-11-12 19:55:17 +00:00
|
|
|
"github.com/docker/docker/container"
|
2017-05-19 22:06:46 +00:00
|
|
|
"github.com/docker/docker/pkg/idtools"
|
2018-04-17 20:50:28 +00:00
|
|
|
volumemounts "github.com/docker/docker/volume/mounts"
|
2015-06-03 16:26:41 +00:00
|
|
|
)
|
2015-05-19 20:05:25 +00:00
|
|
|
|
2015-09-10 02:23:06 +00:00
|
|
|
// setupMounts configures the mount points for a container by appending each
|
2016-03-18 19:43:17 +00: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 12:08:57 +00:00
|
|
|
// It also ensures each of the mounts are lexicographically sorted.
|
2016-03-18 18:53:27 +00:00
|
|
|
|
|
|
|
// BUGBUG TODO Windows containerd. This would be much better if it returned
|
2016-09-27 17:26:59 +00:00
|
|
|
// an array of runtime spec mounts, not container mounts. Then no need to
|
2016-03-18 18:53:27 +00:00
|
|
|
// do multiple transitions.
|
|
|
|
|
|
|
|
func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, error) {
|
|
|
|
var mnts []container.Mount
|
2018-04-17 20:50:28 +00:00
|
|
|
for _, mount := range c.MountPoints { // type is volumemounts.MountPoint
|
2016-03-18 18:53:27 +00:00
|
|
|
if err := daemon.lazyInitializeVolume(c.ID, mount); err != nil {
|
2016-01-12 22:18:57 +00:00
|
|
|
return nil, err
|
2015-12-09 19:39:31 +00:00
|
|
|
}
|
2018-05-17 14:29:52 +00:00
|
|
|
s, err := mount.Setup(c.MountLabel, idtools.IDPair{UID: 0, GID: 0}, nil)
|
2016-09-19 20:57:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-09-10 02:23:06 +00:00
|
|
|
}
|
2016-09-19 20:57:55 +00:00
|
|
|
|
2016-03-18 18:53:27 +00:00
|
|
|
mnts = append(mnts, container.Mount{
|
2015-09-10 02:23:06 +00:00
|
|
|
Source: s,
|
|
|
|
Destination: mount.Destination,
|
|
|
|
Writable: mount.RW,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Sort(mounts(mnts))
|
|
|
|
return mnts, nil
|
2015-04-29 22:53:35 +00:00
|
|
|
}
|
2015-06-08 20:45:28 +00:00
|
|
|
|
2015-09-10 02:23:06 +00:00
|
|
|
// setBindModeIfNull is platform specific processing which is a no-op on
|
|
|
|
// Windows.
|
2018-04-17 20:50:28 +00: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 18:25:35 +00:00
|
|
|
return
|
2015-09-10 02:23:06 +00:00
|
|
|
}
|
2018-01-18 21:55:27 +00:00
|
|
|
|
|
|
|
func (daemon *Daemon) validateBindDaemonRoot(m mount.Mount) (bool, error) {
|
|
|
|
return false, nil
|
|
|
|
}
|