47c56e43 |
// +build !windows
package daemon
import ( |
a793564b |
"fmt" |
47c56e43 |
"os"
"path/filepath"
|
91e197d6 |
containertypes "github.com/docker/docker/api/types/container" |
fc7b904d |
mounttypes "github.com/docker/docker/api/types/mount" |
6bb0d181 |
"github.com/docker/docker/container" |
47c56e43 |
"github.com/docker/docker/pkg/stringid" |
abbbf914 |
"github.com/opencontainers/selinux/go-selinux/label" |
1009e6a4 |
"github.com/sirupsen/logrus" |
47c56e43 |
)
|
0380fbff |
// createContainerOSSpecificSettings performs host-OS specific container create functionality
func (daemon *Daemon) createContainerOSSpecificSettings(container *container.Container, config *containertypes.Config, hostConfig *containertypes.HostConfig) error { |
9112d90b |
if err := daemon.Mount(container); err != nil {
return err
}
defer daemon.Unmount(container)
|
93fbdb69 |
rootIDs := daemon.idMappings.RootPair() |
09cd96c5 |
if err := container.SetupWorkingDirectory(rootIDs); err != nil { |
cde0ed67 |
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() { |
a793564b |
return fmt.Errorf("cannot mount volume over existing file, file exists %s", path) |
47c56e43 |
}
|
fc214b44 |
v, err := daemon.volumes.CreateWithRef(name, hostConfig.VolumeDriver, container.ID, nil, 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 { |
fc7b904d |
if mnt.Volume == nil {
continue
}
if mnt.Type != mounttypes.TypeVolume || !mnt.CopyData { |
b4683327 |
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
} |