浏览代码

Skip existing volumes in volumes-from

Removes the error when a container already has a volume that would otherwise
be created by `Config.VolumesFrom`. Allows restarting containers with a
`Config.VolumesFrom` set.
Greg Thornton 12 年之前
父节点
当前提交
57b49efc98
共有 2 个文件被更改,包括 12 次插入4 次删除
  1. 6 4
      container.go
  2. 6 0
      container_test.go

+ 6 - 4
container.go

@@ -587,7 +587,7 @@ func (container *Container) Start(hostConfig *HostConfig) error {
 		}
 		for volPath, id := range c.Volumes {
 			if _, exists := container.Volumes[volPath]; exists {
-				return fmt.Errorf("The requested volume %s overlap one of the volume of the container %s", volPath, c.ID)
+				continue
 			}
 			if err := os.MkdirAll(path.Join(container.RootfsPath(), volPath), 0755); err != nil {
 				return nil
@@ -602,10 +602,12 @@ func (container *Container) Start(hostConfig *HostConfig) error {
 	// Create the requested volumes if they don't exist
 	for volPath := range container.Config.Volumes {
 		volPath = path.Clean(volPath)
-		// If an external bind is defined for this volume, use that as a source
+		// Skip existing volumes
 		if _, exists := container.Volumes[volPath]; exists {
-			// Skip existing mounts
-		} else if bindMap, exists := binds[volPath]; exists {
+			continue
+		}
+		// If an external bind is defined for this volume, use that as a source
+		if bindMap, exists := binds[volPath]; exists {
 			container.Volumes[volPath] = bindMap.SrcPath
 			if strings.ToLower(bindMap.Mode) == "rw" {
 				container.VolumesRW[volPath] = true

+ 6 - 0
container_test.go

@@ -1333,6 +1333,12 @@ func TestVolumesFromWithVolumes(t *testing.T) {
 	if container.Volumes["/test"] != container2.Volumes["/test"] {
 		t.Fail()
 	}
+
+	// Ensure it restarts successfully
+	_, err = container2.Output()
+	if err != nil {
+		t.Fatal(err)
+	}
 }
 
 func TestOnlyLoopbackExistsWhenUsingDisableNetworkOption(t *testing.T) {