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:
Michael Crosby 2014-05-19 22:18:37 +00:00
Родитель e454be7567
Коммит d535d98100
2 изменённых файлов: 50 добавлений и 33 удалений

Просмотреть файл

@ -168,6 +168,12 @@ func createVolumes(container *Container) error {
return err
}
}
for volPath := range binds {
if err := initializeVolume(container, volPath, binds); err != nil {
return err
}
}
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
} else {
// Do not pass a container as the parameter for the volume creation.
// The graph driver using the container's information ( Image ) to
// create the parent.
@ -273,15 +278,25 @@ func initializeVolume(container *Container, volPath string, binds map[string]Bin
// Do not copy or change permissions if we are mounting from the host
if srcRW && !isBindMount {
if err := copyExistingContents(rootVolPath, srcPath); 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 {
@ -290,11 +305,14 @@ func initializeVolume(container *Container, volPath string, binds map[string]Bin
}
}
var stat syscall.Stat_t
var (
stat syscall.Stat_t
srcStat 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
}
@ -305,6 +323,5 @@ func initializeVolume(container *Container, volPath string, binds map[string]Bin
return err
}
}
}
return nil
}

Просмотреть файл

@ -135,8 +135,8 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf
if arr[0] == "/" {
return nil, nil, cmd, fmt.Errorf("Invalid bind mount: source can't be '/'")
}
dstDir := arr[1]
flVolumes.Set(dstDir)
// after creating the bind mount we want to delete it from the flVolumes values because
// we do not want bind mounts being committed to image configs
binds = append(binds, bind)
flVolumes.Delete(bind)
} else if bind == "/" {