先上报错:

panic: assignment to entry in nil map

goroutine 1 [running]:
github.com/docker/cli/cli/config/credentials.(*fileStore).Store(0xc000628130, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0xc00003a5d0, ...}, ...})
        /go/src/github.com/docker/cli/cli/config/credentials/file_store.go:55 +0x49
github.com/docker/cli/cli/config/credentials.(*nativeStore).Store(0xc0004a4180, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0xc00003a5d0, ...}, ...})
        /go/src/github.com/docker/cli/cli/config/credentials/native_store.go:95 +0xb5
github.com/docker/cli/cli/command/registry.runLogin({0x13e5cd8, 0xc00039a1e0}, {{0xc00003a5d0, 0x21}, {0xc0000401d3, 0x6}, {0x0, 0x0}, 0x0})
        /go/src/github.com/docker/cli/cli/command/registry/login.go:156 +0x55d
github.com/docker/cli/cli/command/registry.NewLoginCommand.func1(0xc000005b00?, {0xc000091c80?, 0x1?, 0x2?})
        /go/src/github.com/docker/cli/cli/command/registry/login.go:46 +0x72
        /go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:940 +0x862
        /go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:1068 +0x3bd
github.com/docker/cli/vendor/github.com/spf13/cobra.(*Command).Execute(...)
        /go/src/github.com/docker/cli/vendor/github.com/spf13/cobra/command.go:992
main.runDocker(0x0?)
        /go/src/github.com/docker/cli/cmd/docker/docker.go:263 +0x4b7
main.main()
        /go/src/github.com/docker/cli/cmd/docker/docker.go:274 +0x97

默认的镜像仓库是官方的 Docker Hub,当我登录到阿里云的镜像仓库时:

docker login --username=<username> registry.cn-hangzhou.aliyuncs.com

出现了 panic 错误,解决做法是先 logout

docker logout
docker login --username=<username> registry.cn-hangzhou.aliyuncs.com

Reference

https://forums.docker.com/t/panic-assignment-to-entry-in-nil-map/136806/11