Ver Fonte

Merge pull request #17945 from tonistiigi/fix-windows-pull

Fix docker pull on windows
Tibor Vass há 9 anos atrás
pai
commit
59fe485f0d
4 ficheiros alterados com 32 adições e 2 exclusões
  1. 3 1
      graph/graph.go
  2. 8 0
      graph/graph_unix.go
  3. 8 0
      graph/graph_windows.go
  4. 13 1
      graph/pull_v2.go

+ 3 - 1
graph/graph.go

@@ -720,7 +720,9 @@ func (graph *Graph) storeImage(id, parent string, config []byte, layerData io.Re
 		return err
 	}
 
-	if img.ParentID.Validate() == nil && parent != img.ParentID.Hex() {
+	if (img.ParentID.Validate() == nil && parent != img.ParentID.Hex()) || (allowBaseParentImage && img.ParentID == "" && parent != "") {
+		// save compatibilityID parent if it doesn't match parentID
+		// on windows always save a parent file pointing to the base layer
 		if err := ioutil.WriteFile(filepath.Join(root, parentFileName), []byte(parent), 0600); err != nil {
 			return err
 		}

+ 8 - 0
graph/graph_unix.go

@@ -0,0 +1,8 @@
+// +build !windows
+
+package graph
+
+// allowBaseParentImage allows images to define a custom parent that is not
+// transported with push/pull but already included with the installation.
+// Only used in Windows.
+const allowBaseParentImage = false

+ 8 - 0
graph/graph_windows.go

@@ -0,0 +1,8 @@
+// +build windows
+
+package graph
+
+// allowBaseParentImage allows images to define a custom parent that is not
+// transported with push/pull but already included with the installation.
+// Only used in Windows.
+const allowBaseParentImage = true

+ 13 - 1
graph/pull_v2.go

@@ -500,7 +500,8 @@ func fixManifestLayers(m *schema1.Manifest) error {
 		}
 	}
 
-	if images[len(images)-1].Parent != "" {
+	if images[len(images)-1].Parent != "" && !allowBaseParentImage {
+		// Windows base layer can point to a base layer parent that is not in manifest.
 		return errors.New("Invalid parent ID in the base layer of the image.")
 	}
 
@@ -548,6 +549,17 @@ func (p *v2Puller) getImageInfos(m *schema1.Manifest) ([]contentAddressableDescr
 
 	p.attemptIDReuse(imgs)
 
+	// reset the base layer parent for windows
+	if allowBaseParentImage {
+		var base struct{ Parent string }
+		if err := json.Unmarshal(imgs[len(imgs)-1].v1Compatibility, &base); err != nil {
+			return nil, err
+		}
+		if base.Parent != "" {
+			imgs[len(imgs)-1].parent = base.Parent
+		}
+	}
+
 	return imgs, nil
 }