Skip to content

Commit 8437d0a

Browse files
author
John Howard
committed
Windows: Fix regression pulling linux images
Signed-off-by: John Howard <[email protected]>
1 parent 93e8aff commit 8437d0a

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

distribution/pull_v2.go

+32-9
Original file line numberDiff line numberDiff line change
@@ -550,15 +550,36 @@ func (p *v2Puller) pullSchema2(ctx context.Context, ref reference.Named, mfst *s
550550
)
551551

552552
// https://github.com/docker/docker/issues/24766 - Err on the side of caution,
553-
// explicitly blocking images intended for linux from the Windows daemon
554-
if runtime.GOOS == "windows" && unmarshalledConfig.OS == "linux" {
555-
return "", "", fmt.Errorf("image operating system %q cannot be used on this platform", unmarshalledConfig.OS)
553+
// explicitly blocking images intended for linux from the Windows daemon. On
554+
// Windows, we do this before the attempt to download, effectively serialising
555+
// the download slightly slowing it down. We have to do it this way, as
556+
// chances are the download of layers itself would fail due to file names
557+
// which aren't suitable for NTFS. At some point in the future, if a similar
558+
// check to block Windows images being pulled on Linux is implemented, it
559+
// may be necessary to perform the same type of serialisation.
560+
if runtime.GOOS == "windows" {
561+
configJSON, unmarshalledConfig, err = receiveConfig(configChan, errChan)
562+
if err != nil {
563+
return "", "", err
564+
}
565+
566+
if unmarshalledConfig.RootFS == nil {
567+
return "", "", errRootFSInvalid
568+
}
569+
570+
if unmarshalledConfig.OS == "linux" {
571+
return "", "", fmt.Errorf("image operating system %q cannot be used on this platform", unmarshalledConfig.OS)
572+
}
556573
}
557574

558575
downloadRootFS = *image.NewRootFS()
559576

560577
rootFS, release, err := p.config.DownloadManager.Download(ctx, downloadRootFS, descriptors, p.config.ProgressOutput)
561578
if err != nil {
579+
if configJSON != nil {
580+
// Already received the config
581+
return "", "", err
582+
}
562583
select {
563584
case err = <-errChan:
564585
return "", "", err
@@ -573,13 +594,15 @@ func (p *v2Puller) pullSchema2(ctx context.Context, ref reference.Named, mfst *s
573594
}
574595
defer release()
575596

576-
configJSON, unmarshalledConfig, err = receiveConfig(configChan, errChan)
577-
if err != nil {
578-
return "", "", err
579-
}
597+
if configJSON == nil {
598+
configJSON, unmarshalledConfig, err = receiveConfig(configChan, errChan)
599+
if err != nil {
600+
return "", "", err
601+
}
580602

581-
if unmarshalledConfig.RootFS == nil {
582-
return "", "", errRootFSInvalid
603+
if unmarshalledConfig.RootFS == nil {
604+
return "", "", errRootFSInvalid
605+
}
583606
}
584607

585608
// The DiffIDs returned in rootFS MUST match those in the config.

integration-cli/docker_cli_pull_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,10 @@ func (s *DockerRegistryAuthHtpasswdSuite) TestPullNoCredentialsNotFound(c *check
272272
c.Assert(err, check.NotNil, check.Commentf(out))
273273
c.Assert(out, checker.Contains, "Error: image busybox:latest not found")
274274
}
275+
276+
// Regression test for https://github.com/docker/docker/issues/26429
277+
func (s *DockerSuite) TestPullLinuxImageFailsOnWindows(c *check.C) {
278+
testRequires(c, DaemonIsWindows, Network)
279+
_, _, err := dockerCmdWithError("pull", "ubuntu")
280+
c.Assert(err.Error(), checker.Contains, "cannot be used on this platform")
281+
}

0 commit comments

Comments
 (0)