Pulling from private repo in kubernetes fails with "The Secret "docker-credentials" is invalid: data[.dockerconfigjson]: Required value"

1/23/2020

I am trying to pull images from my docker hub repo. I followed the documentation found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

However after typing in the command:

kubectl create secret generic docker-credentials --from-file=/my/local/path/to/.docker/config.json --type=kubernetes.io/dockerconfigjson

I get the following error:

The Secret "docker-credentials" is invalid: data[.dockerconfigjson]: Required value

I tried deleting the config.json and re-logging in, but with no change in behavior.

docker version prints:

Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        633a0ea838
 Built:             Wed Nov 13 07:29:52 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:       633a0ea838
  Built:            Wed Nov 13 07:28:22 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

kubectl version prints:

Client Version: version.Info{
  Major:"1",
  Minor:"17",
  GitVersion:"v1.17.2",
  GitCommit:"59603c6e503c87169aea6106f57b9f242f64df89",
  GitTreeState:"clean",
  BuildDate:"2020-01-18T23:30:10Z",
  GoVersion:"go1.13.5",
  Compiler:"gc",
  Platform:"linux/amd64"
}
Server Version: version.Info{
  Major:"1",
  Minor:"15",
  GitVersion:"v1.15.2",
  GitCommit:"f6278300bebbb750328ac16ee6dd3aa7d3549568",
  GitTreeState:"clean",
  BuildDate:"2019-08-05T09:15:22Z",
  GoVersion:"go1.12.5",
  Compiler:"gc",
  Platform:"linux/amd64"
}

the config.json looks like:

{
    "auths": {
        "https://index.docker.io/v1/": {
            "auth": "secret-stuff"
        }
    },
    "HttpHeaders": {
        "User-Agent": "Docker-Client/19.03.5 (linux)"
    }
}

For the moment I can enter the credentials manually, but I'd like to understand what's going wrong. any help would be appreciated!

-- Marcus Ruddick
docker
kubernetes
private-repository

2 Answers

1/24/2020

You didn't run the docker login command with docker private repository, hence the config.json file doesn't have the authentication informations. You can refer the below sample file.

Example:

  {
    "auths": {

     "https://dockerhub.xxxxx.com": {
        "auth": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
        "email": "xxxxx@xxxxx.com"
     }
   },
   "HttpHeaders": {
      "User-Agent": "Docker-Client/18.06.1-ce (linux)"
   }
 }
-- Subramanian Manickam
Source: StackOverflow

1/24/2020

While creating the secret you did not specified the Type of a file you will be reading from so kubectl did not read the file properly.

List of types is as follows:

SecretTypeOpaque SecretType = "Opaque"
[...]
SecretTypeServiceAccountToken SecretType = "kubernetes.io/service-account-token"
[...]
SecretTypeDockercfg SecretType = "kubernetes.io/dockercfg"
[...]
SecretTypeDockerConfigJSON SecretType = "kubernetes.io/dockerconfigjson"
[...]
SecretTypeBasicAuth SecretType = "kubernetes.io/basic-auth"
[...]
SecretTypeSSHAuth SecretType = "kubernetes.io/ssh-auth"
[...]
SecretTypeTLS SecretType = "kubernetes.io/tls"
[...]
SecretTypeBootstrapToken SecretType = "bootstrap.kubernetes.io/token"

which you can find at Kubernetes GitHub kubernetes/pkg/apis/core/types.go

The correct command in your case would be kubectl create secret generic docker-credentials --from-file=.dockerconfigjson=path/to/.docker/config.json --type=kubernetes.io/dockerconfigjson

Please give attention into --from-file=.dockerconfigjson=path/to/.docker/config.json, you should be editing only path/to/.docker/config.json

-- Crou
Source: StackOverflow