Fix: Failed Start breaks VolumesFrom

Running parseVolumesFromSpec on all VolumesFrom specs before initialize
any mounts endures that we don't leave container.Volumes in an
inconsistent (partially initialized) if one of out mount groups is not
available (e.g. the container we're trying to mount from does not
exist).

Keeping container.Volumes in a consistent state ensures that next time
we Start() the container, it'll run prepareVolumes() again.

The attached test demonstrates that when a container fails to start due
to a missing container specified in VolumesFrom, it "remembers" a Volume
that worked.

Fixes: #8726

Signed-off-by: Thomas Orozco <thomas@orozco.fr>

Conflicts:
	integration-cli/docker_cli_start_test.go
		cli integration test
Upstream-commit: 967f80f3cceb96f85a4795d42eeb7b84ae0ce24a
Component: engine
This commit is contained in:
Thomas Orozco
2014-10-23 14:50:06 +02:00
committed by unclejack
parent 0aef38f7a2
commit f3c864f896
2 changed files with 36 additions and 2 deletions

View File

@ -191,15 +191,20 @@ func parseBindMountSpec(spec string) (string, string, bool, error) {
func (container *Container) applyVolumesFrom() error {
volumesFrom := container.hostConfig.VolumesFrom
mountGroups := make([]map[string]*Mount, 0, len(volumesFrom))
for _, spec := range volumesFrom {
mounts, err := parseVolumesFromSpec(container.daemon, spec)
mountGroup, err := parseVolumesFromSpec(container.daemon, spec)
if err != nil {
return err
}
mountGroups = append(mountGroups, mountGroup)
}
for _, mounts := range mountGroups {
for _, mnt := range mounts {
mnt.container = container
if err = mnt.initialize(); err != nil {
if err := mnt.initialize(); err != nil {
return err
}
}