47c56e43 |
// +build !windows
package daemon
import (
"os"
"path/filepath"
|
b4683327 |
"github.com/Sirupsen/logrus" |
6bb0d181 |
"github.com/docker/docker/container" |
a283a30f |
derr "github.com/docker/docker/errors" |
47c56e43 |
"github.com/docker/docker/pkg/stringid" |
907407d0 |
containertypes "github.com/docker/engine-api/types/container" |
47c56e43 |
"github.com/opencontainers/runc/libcontainer/label"
)
// createContainerPlatformSpecificSettings performs platform specific container create functionality |
e91c8a9a |
func (daemon *Daemon) createContainerPlatformSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error { |
9112d90b |
if err := daemon.Mount(container); err != nil {
return err
}
defer daemon.Unmount(container)
|
cde0ed67 |
if err := container.SetupWorkingDirectory(); err != nil {
return err
}
|
47c56e43 |
for spec := range config.Volumes { |
cec31abf |
name := stringid.GenerateNonCryptoID()
destination := filepath.Clean(spec) |
8e5bb8fd |
|
47c56e43 |
// Skip volumes for which we already have something mounted on that
// destination because of a --volume-from. |
6bb0d181 |
if container.IsDestinationMounted(destination) { |
47c56e43 |
continue
}
path, err := container.GetResourcePath(destination)
if err != nil {
return err
}
stat, err := os.Stat(path)
if err == nil && !stat.IsDir() { |
f7d4b4fe |
return derr.ErrorCodeMountOverFile.WithArgs(path) |
47c56e43 |
}
|
e91c8a9a |
v, err := daemon.volumes.CreateWithRef(name, hostConfig.VolumeDriver, container.ID, nil) |
47c56e43 |
if err != nil {
return err
} |
b3b7eb27 |
|
55a601e3 |
if err := label.Relabel(v.Path(), container.MountLabel, true); err != nil { |
47c56e43 |
return err
}
|
b4683327 |
container.AddMountPointWithVolume(destination, v, true)
}
return daemon.populateVolumes(container)
}
// populateVolumes copies data from the container's rootfs into the volume for non-binds.
// this is only called when the container is created.
func (daemon *Daemon) populateVolumes(c *container.Container) error {
for _, mnt := range c.MountPoints {
// skip binds and volumes referenced by other containers (ie, volumes-from)
if mnt.Driver == "" || mnt.Volume == nil || len(daemon.volumes.Refs(mnt.Volume)) > 1 {
continue |
47c56e43 |
}
|
b4683327 |
logrus.Debugf("copying image data from %s:%s, to %s", c.ID, mnt.Destination, mnt.Name)
if err := c.CopyImagePathContent(mnt.Volume, mnt.Destination); err != nil {
return err
} |
47c56e43 |
}
return nil
} |