diff --git a/cmd/dockerd/daemon.go b/cmd/dockerd/daemon.go index 3713321db4..375019c4f6 100644 --- a/cmd/dockerd/daemon.go +++ b/cmd/dockerd/daemon.go @@ -69,14 +69,14 @@ func NewDaemonCli() *DaemonCli { daemonConfig.LogConfig.Config = make(map[string]string) daemonConfig.ClusterOpts = make(map[string]string) - if runtime.GOOS != "linux" { - daemonConfig.V2Only = true - } - daemonConfig.InstallFlags(flag.CommandLine, presentInHelp) configFile := flag.CommandLine.String([]string{daemonConfigFileFlag}, defaultDaemonConfigFile, "Daemon configuration file") flag.CommandLine.Require(flag.Exact, 0) + if runtime.GOOS != "linux" { + daemonConfig.V2Only = true + } + return &DaemonCli{ Config: daemonConfig, commonFlags: cliflags.InitCommonFlags(), diff --git a/cmd/dockerd/daemon_test.go b/cmd/dockerd/daemon_test.go index c16e11aec9..f404bf7fc5 100644 --- a/cmd/dockerd/daemon_test.go +++ b/cmd/dockerd/daemon_test.go @@ -267,7 +267,7 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) { configFile := f.Name() defer os.Remove(configFile) - f.Write([]byte(`{"registry-mirrors": ["https://mirrors.docker.com"], "insecure-registries": ["https://insecure.docker.com"], "disable-legacy-registry": true}`)) + f.Write([]byte(`{"registry-mirrors": ["https://mirrors.docker.com"], "insecure-registries": ["https://insecure.docker.com"]}`)) f.Close() loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile) @@ -287,8 +287,4 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) { if len(r) != 1 { t.Fatalf("expected 1 insecure registries, got %d", len(r)) } - - if !loadedConfig.V2Only { - t.Fatal("expected disable-legacy-registry to be true, got false") - } } diff --git a/cmd/dockerd/daemon_unix_test.go b/cmd/dockerd/daemon_unix_test.go index a72468eddb..2d8bebda08 100644 --- a/cmd/dockerd/daemon_unix_test.go +++ b/cmd/dockerd/daemon_unix_test.go @@ -4,6 +4,7 @@ package main import ( "io/ioutil" + "os" "testing" cliflags "github.com/docker/docker/cli/flags" @@ -210,3 +211,32 @@ func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) { t.Fatal("expected userland proxy to be enabled, got disabled") } } + +func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) { + c := &daemon.Config{} + common := &cliflags.CommonFlags{} + flags := mflag.NewFlagSet("test", mflag.ContinueOnError) + c.ServiceOptions.InstallCliFlags(flags, absentFromHelp) + + f, err := ioutil.TempFile("", "docker-config-") + if err != nil { + t.Fatal(err) + } + configFile := f.Name() + defer os.Remove(configFile) + + f.Write([]byte(`{"disable-legacy-registry": true}`)) + f.Close() + + loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile) + if err != nil { + t.Fatal(err) + } + if loadedConfig == nil { + t.Fatal("expected configuration, got nil") + } + + if !loadedConfig.V2Only { + t.Fatal("expected disable-legacy-registry to be true, got false") + } +} diff --git a/distribution/push_v2.go b/distribution/push_v2.go index 7d331f43d2..cd919e2f52 100644 --- a/distribution/push_v2.go +++ b/distribution/push_v2.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io" + "runtime" "sync" "github.com/Sirupsen/logrus" @@ -169,6 +170,11 @@ func (p *v2Pusher) pushV2Tag(ctx context.Context, ref reference.NamedTagged, ima putOptions := []distribution.ManifestServiceOption{distribution.WithTag(ref.Tag())} if _, err = manSvc.Put(ctx, manifest, putOptions...); err != nil { + if runtime.GOOS == "windows" { + logrus.Warnf("failed to upload schema2 manifest: %v", err) + return err + } + logrus.Warnf("failed to upload schema2 manifest: %v - falling back to schema1", err) manifestRef, err := distreference.WithTag(p.repo.Named(), ref.Tag()) diff --git a/registry/config.go b/registry/config.go index e349660e32..90723bfd51 100644 --- a/registry/config.go +++ b/registry/config.go @@ -77,7 +77,7 @@ func (options *ServiceOptions) InstallCliFlags(cmd *flag.FlagSet, usageFn func(s insecureRegistries := opts.NewNamedListOptsRef("insecure-registries", &options.InsecureRegistries, ValidateIndexName) cmd.Var(insecureRegistries, []string{"-insecure-registry"}, usageFn("Enable insecure registry communication")) - cmd.BoolVar(&options.V2Only, []string{"-disable-legacy-registry"}, false, usageFn("Disable contacting legacy registries")) + options.installCliPlatformFlags(cmd, usageFn) } // newServiceConfig returns a new instance of ServiceConfig diff --git a/registry/config_unix.go b/registry/config_unix.go index b81d24933c..bae33970cc 100644 --- a/registry/config_unix.go +++ b/registry/config_unix.go @@ -2,6 +2,10 @@ package registry +import ( + flag "github.com/docker/docker/pkg/mflag" +) + var ( // CertsDir is the directory where certificates are stored CertsDir = "/etc/docker/certs.d" @@ -14,3 +18,8 @@ var ( func cleanPath(s string) string { return s } + +// installCliPlatformFlags handles any platform specific flags for the service. +func (options *ServiceOptions) installCliPlatformFlags(cmd *flag.FlagSet, usageFn func(string) string) { + cmd.BoolVar(&options.V2Only, []string{"-disable-legacy-registry"}, false, usageFn("Disable contacting legacy registries")) +} diff --git a/registry/config_windows.go b/registry/config_windows.go index 82bc4afea7..d8b7f7eae7 100644 --- a/registry/config_windows.go +++ b/registry/config_windows.go @@ -4,6 +4,8 @@ import ( "os" "path/filepath" "strings" + + flag "github.com/docker/docker/pkg/mflag" ) // CertsDir is the directory where certificates are stored @@ -16,3 +18,8 @@ var CertsDir = os.Getenv("programdata") + `\docker\certs.d` func cleanPath(s string) string { return filepath.FromSlash(strings.Replace(s, ":", "", -1)) } + +// installCliPlatformFlags handles any platform specific flags for the service. +func (options *ServiceOptions) installCliPlatformFlags(cmd *flag.FlagSet, usageFn func(string) string) { + // No Windows specific flags. +}