Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker unauthorized: authentication required - upon push with successful login

Tags:

docker

You'll need to log in to Docker.

Step 1: log in to docker hub

Based on @KaraPirinc's comment, in Docker version 17 in order to log in:

docker login -u username --password-stdin

Then enter your password when asked.

Step 2: create a repository in the docker hub.

Let's say "mysqlserver:sql".

docker push <user username>/mysqlserver:sql

OK! never mind; I found the solution. with 403 Suspected that the HTTP is not going to the right URL.

Change the file which has the login credentials stored the ~/.docker/config.json from the default generated of

{
        "auths": {
                "docker.io": {
                        "auth": "XXXXXXXXXXXXX",
                        "email": "[email protected]"
                }
        }
}

to - Note the change from docker.io -> index.docker.io/v1. That is the change.

{
        "auths": {
                "https://index.docker.io/v1/": {
                        "auth": "XXXXXXXXXXXXX",
                        "email": "[email protected]"
                }
        }
}

Hope that helps.

Note that the auth field should be 'username:password" base64 encoded. for example: "username:password" base64 encoded is "dXNlcm5hbWU6cGFzc3dvcmQ="

so your file would contain:

"auth": "dXNlcm5hbWU6cGFzc3dvcmQ="

The solution you posted is not working for me...

This is what works for me:

  1. Create the repository with the desired name.

  2. When committing the image, name the image like the repository, including the username <dockerusername>/desired-name. For example, radu/desired-name.


if you are using heroku, be sure you did not forget to "heroku container:login" before pushing.


The problem newbies face is that we tend to treat docker hub repository just like a maven repository and think that it might contain many a different files, folders and other contents.

A docker repository on the other hand is just a single image, it does not contain anything else. It can hold different versions of the same image, but its going to contain just one image.

So, name your repository on docker hub the same name as the image you want to push into it, and use your dockerhub username as prefix. For eg, if your username is myusername and your image name is docker-whale , make sure to name your dockerhub repository as docker-whale and use the below commands to tag and push your image to repository:

docker logout                                   # to make sure you're logged out and not cause any clashes
docker tag <imageId> myusername/docker-whale    # use :1.0.0 for specific version, default is 'latest'
docker login --username=myusername              # use the username/pwd to login to docker hub
docker push myusername/docker-whale             # use :1.0.0 for pushing specific version, default is 'latest'

I had the same problem but i fixed it with push with specified url. as: docker login -u https://index.docker.io/v1/

console output:

The push refers to a repository [docker.io/<username>/richcity]
adc9144127c1: Preparing 
4db5654f7a64: Preparing 
ce71ae73bc60: Preparing 
e8e980243ee4: Preparing 
d773e991f7d2: Preparing 
bae23f4bbe95: Waiting 
5f70bf18a086: Waiting 
3d3e4e34386e: Waiting 
e72d5d9d5d30: Waiting 
8d1d75696199: Waiting 
bdf5b19f60a4: Waiting 
c8bd8922fbb7: Waiting 
unauthorized: authentication required

1010deiMac:dockerspace whoami$ docker login -u <username> https://index.docker.io/v1/
Password: 
Login Succeeded
1010deiMac:dockerspace whoami$ docker push <username>/richcity 
The push refers to a repository [docker.io/<username>/richcity]
adc9144127c1: Pushed 
4db5654f7a64: Pushed 
ce71ae73bc60: Pushed 
e8e980243ee4: Pushed 
d773e991f7d2: Pushed 
bae23f4bbe95: Pushed 
5f70bf18a086: Pushed 
3d3e4e34386e: Pushing [=============>                                     ] 45.07 MB/165.4 MB
e72d5d9d5d30: Pushed 
8d1d75696199: Pushing [>                                                  ] 1.641 MB/118.1 MB
bdf5b19f60a4: Pushing [============>                                      ]   142 MB/568.4 MB
c8bd8922fbb7: Pushing [========================>                          ] 59.44 MB/121.8 MB