瀏覽代碼

Stop trying to load images on an incompatible OS

Signed-off-by: John Stephens <johnstep@docker.com>
John Stephens 8 年之前
父節點
當前提交
b9255e4a53
共有 1 個文件被更改,包括 28 次插入1 次删除
  1. 28 1
      image/tarexport/load.go

+ 28 - 1
image/tarexport/load.go

@@ -79,6 +79,9 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool)
 		if err != nil {
 			return err
 		}
+		if err := checkCompatibleOS(img.OS); err != nil {
+			return err
+		}
 		var rootFS image.RootFS
 		rootFS = *img.RootFS
 		rootFS.DiffIDs = nil
@@ -292,11 +295,18 @@ func (l *tarexporter) legacyLoadImage(oldID, sourceDir string, loadedMap map[str
 		return err
 	}
 
-	var img struct{ Parent string }
+	var img struct {
+		OS     string
+		Parent string
+	}
 	if err := json.Unmarshal(imageJSON, &img); err != nil {
 		return err
 	}
 
+	if err := checkCompatibleOS(img.OS); err != nil {
+		return err
+	}
+
 	var parentID image.ID
 	if img.Parent != "" {
 		for {
@@ -402,3 +412,20 @@ func checkValidParent(img, parent *image.Image) bool {
 	}
 	return true
 }
+
+func checkCompatibleOS(os string) error {
+	// TODO @jhowardmsft LCOW - revisit for simultaneous platforms
+	platform := runtime.GOOS
+	if system.LCOWSupported() {
+		platform = "linux"
+	}
+	// always compatible if the OS matches; also match an empty OS
+	if os == platform || os == "" {
+		return nil
+	}
+	// for compatibility, only fail if the image or runtime OS is Windows
+	if os == "windows" || platform == "windows" {
+		return fmt.Errorf("cannot load %s image on %s", os, platform)
+	}
+	return nil
+}