LCOW: Auto-select OS

Signed-off-by: John Howard <jhoward@microsoft.com>

Addresses https://github.com/moby/moby/pull/35089#issuecomment-367802698.
This change enables the daemon to automatically select an image under LCOW
that can be used if the API doesn't specify an explicit platform.

For example:

FROM supertest2014/nyan
ADD Dockerfile /

And docker build . will download the linux image (not a multi-manifest image)

And similarly docker pull ubuntu will match linux/amd64
Upstream-commit: 35193c0e7dc301e1d2f6ea96e0ce34ffd2d4b88d
Component: engine
This commit is contained in:
John Howard
2018-06-26 11:37:43 -07:00
committed by Tonis Tiigi
parent f0140f8d7c
commit 758ffaf745
9 changed files with 49 additions and 40 deletions
@@ -228,7 +228,7 @@ func (d *dispatchRequest) getOsFromFlagsAndStage(stageOS string) string {
// multi-arch aware yet, it is guaranteed to only hold the OS part here.
return d.builder.options.Platform
default:
return runtime.GOOS
return "" // Auto-select
}
}
@@ -247,9 +247,9 @@ func (d *dispatchRequest) getImageOrStage(name string, stageOS string) (builder.
imageImage.OS = runtime.GOOS
if runtime.GOOS == "windows" {
switch os {
case "windows", "":
case "windows":
return nil, errors.New("Windows does not support FROM scratch")
case "linux":
case "linux", "":
if !system.LCOWSupported() {
return nil, errors.New("Linux containers are not supported on this system")
}