mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Don't save bind mounts in image
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
e454be7567
commit
d535d98100
2 changed files with 50 additions and 33 deletions
|
@ -168,6 +168,12 @@ func createVolumes(container *Container) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for volPath := range binds {
|
||||||
|
if err := initializeVolume(container, volPath, binds); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +232,6 @@ func initializeVolume(container *Container, volPath string, binds map[string]Bin
|
||||||
}
|
}
|
||||||
// Otherwise create an directory in $ROOT/volumes/ and use that
|
// Otherwise create an directory in $ROOT/volumes/ and use that
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Do not pass a container as the parameter for the volume creation.
|
// Do not pass a container as the parameter for the volume creation.
|
||||||
// The graph driver using the container's information ( Image ) to
|
// The graph driver using the container's information ( Image ) to
|
||||||
// create the parent.
|
// create the parent.
|
||||||
|
@ -273,38 +278,50 @@ func initializeVolume(container *Container, volPath string, binds map[string]Bin
|
||||||
|
|
||||||
// Do not copy or change permissions if we are mounting from the host
|
// Do not copy or change permissions if we are mounting from the host
|
||||||
if srcRW && !isBindMount {
|
if srcRW && !isBindMount {
|
||||||
volList, err := ioutil.ReadDir(rootVolPath)
|
if err := copyExistingContents(rootVolPath, srcPath); err != nil {
|
||||||
if err != nil {
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func copyExistingContents(rootVolPath, srcPath string) error {
|
||||||
|
volList, err := ioutil.ReadDir(rootVolPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(volList) > 0 {
|
||||||
|
srcList, err := ioutil.ReadDir(srcPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(srcList) == 0 {
|
||||||
|
// If the source volume is empty copy files from the root into the volume
|
||||||
|
if err := archive.CopyWithTar(rootVolPath, srcPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
stat syscall.Stat_t
|
||||||
|
srcStat syscall.Stat_t
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := syscall.Stat(rootVolPath, &stat); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := syscall.Stat(srcPath, &srcStat); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Change the source volume's ownership if it differs from the root
|
||||||
|
// files that were just copied
|
||||||
|
if stat.Uid != srcStat.Uid || stat.Gid != srcStat.Gid {
|
||||||
|
if err := os.Chown(srcPath, int(stat.Uid), int(stat.Gid)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(volList) > 0 {
|
|
||||||
srcList, err := ioutil.ReadDir(srcPath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(srcList) == 0 {
|
|
||||||
// If the source volume is empty copy files from the root into the volume
|
|
||||||
if err := archive.CopyWithTar(rootVolPath, srcPath); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var stat syscall.Stat_t
|
|
||||||
if err := syscall.Stat(rootVolPath, &stat); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var srcStat syscall.Stat_t
|
|
||||||
if err := syscall.Stat(srcPath, &srcStat); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// Change the source volume's ownership if it differs from the root
|
|
||||||
// files that were just copied
|
|
||||||
if stat.Uid != srcStat.Uid || stat.Gid != srcStat.Gid {
|
|
||||||
if err := os.Chown(srcPath, int(stat.Uid), int(stat.Gid)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,8 +135,8 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
|
||||||
if arr[0] == "/" {
|
if arr[0] == "/" {
|
||||||
return nil, nil, cmd, fmt.Errorf("Invalid bind mount: source can't be '/'")
|
return nil, nil, cmd, fmt.Errorf("Invalid bind mount: source can't be '/'")
|
||||||
}
|
}
|
||||||
dstDir := arr[1]
|
// after creating the bind mount we want to delete it from the flVolumes values because
|
||||||
flVolumes.Set(dstDir)
|
// we do not want bind mounts being committed to image configs
|
||||||
binds = append(binds, bind)
|
binds = append(binds, bind)
|
||||||
flVolumes.Delete(bind)
|
flVolumes.Delete(bind)
|
||||||
} else if bind == "/" {
|
} else if bind == "/" {
|
||||||
|
|
Loading…
Add table
Reference in a new issue