docker unauthorized: authentication required - upo

2019-01-08 19:27发布

问题:

While pushing the docker image (after successful login) from my host I am getting "unauthorized: authentication required".

Details below.

-bash-4.2# docker login --username=asamba --email=anand.sambamoorthy@gmail.com
WARNING: login credentials saved in /root/.docker/config.json
*Login Succeeded*
-bash-4.2#
-bash-4.2# docker push asamba/docker-whale

Do you really want to push to public registry? [y/n]: y
The push refers to a repository [docker.io/asamba/docker-whale] (len: 0)
faa2fa357a0e: Preparing
unauthorized: authentication required
  • Docker version: 1.9.1 (both client and server)
  • http://hub.docker.com has the repo created as well (asamba/docker-whale).

The /var/log/messages shows 403, I dont know if this docker. See below.

Apr 16 11:39:03 localhost journal: time="2016-04-16T11:39:03.884872524Z" level=info msg="{Action=push, Username=asamba, LoginUID=1001, PID=2125}"
Apr 16 11:39:03 localhost journal: time="2016-04-16T11:39:03.884988574Z" level=error msg="Handler for POST /v1.21/images/asamba/docker-whale/push returned error: Error: Status 403 trying to push repository asamba/docker-whale to official registry: needs to be forced"
Apr 16 11:39:03 localhost journal: time="2016-04-16T11:39:03.885013241Z" level=error msg="HTTP Error" err="Error: Status 403 trying to push repository asamba/docker-whale to official registry: needs to be forced" statusCode=403
Apr 16 11:39:05 localhost journal: time="2016-04-16T11:39:05.420188969Z" level=info msg="{Action=push, Username=asamba, LoginUID=1001, PID=2125}"
Apr 16 11:39:06 localhost kernel: XFS (dm-4): Mounting V4 Filesystem
Apr 16 11:39:06 localhost kernel: XFS (dm-4): Ending clean mount
Apr 16 11:39:07 localhost kernel: XFS (dm-4): Unmounting Filesystem

Any help is appreciated, please let me know if you need further info. I did the push with -f as well. No luck!

回答1:

I also had the same issue.This is how I resolve it.

Step 1: log in to docker hub

docker login --username=<user username> --email=<user email address>

Step2: create a repository in the docker hub. let's say "mysqlserver:sql".

docker push <user username>/mysqlserver:sql

Edit(13/08/2017)

Based on @KaraPirinc's comment, in docker version 17 in order to log in (Step 1),

docker login -u username -p password


回答2:

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.



回答3:

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": "x.y@gmail.com"
                }
        }
}

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

{
        "auths": {
                "https://index.docker.io/v1/": {
                        "auth": "XXXXXXXXXXXXX",
                        "email": "x.y@gmail.com"
                }
        }
}

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="


回答4:

I was running into a similar issue with a similarly unhelpful error message, but it turned out to be because I was trying to push an image that I had built against a docker-machine managed instance.

When I logged into the instance itself, did docker login and docker push everything worked fine.



回答5:

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


回答6:

Though the standard process is to login and then push to docker registry, trick to get over this particular problem is to login by providing username and password in same line.

So :

docker login -u xxx -p yyy sampledockerregistry.com/myapp 
docker push sampledockerregistry.com/myapp

Works

whereas

docker login sampledockerregistry.com 
username : xxx
password : yyy
Login Succeeded

docker push sampledockerregistry.com/myapp

Fails



回答7:

Even I logged in and checked all the configuration, it still does not work !!!

It turned out that when I build my docker, I forget to put my username before the repo name

docker build docker-meteor-build 

(build successfully)

And then when I pushed to my repository, I used

docker push myname/docker-meteor-build 

It will show the unauthorized authentication required

So, solution is then name of build and the push should be exactly the same

docker build myname/docker-meteor-build 
docker push myname/docker-meteor-build 


回答8:

If you are pushing a new private image for the first time, make sure your subscription supports this extra image.

Docker allows you to have 6 private images named, even if you only pay for 5, but not to push that 6th image. The lack of an informative message is confusing and irritating.



回答9:

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'


回答10:

What worked for me was to create a new repository and rename the image with

$ docker tag image_id myname/server:latest



回答11:

Here the solution for my case ( private repos, free account plan)

https://success.docker.com/Datacenter/Solve/Getting_%22unauthorized%3A_authentication_required%22_when_trying_to_push_image_to_DTR

The image build name to push has to have the same name of the repos.

Example: repos on docker hub is: accountName/resposName image build name "accountName/resposName" -> docker build -t accountName/resposName

then type docker push accountName/resposName:latest

That's all.



回答12:

Make sure you have more slots for private images.

In my case I converted a user into an organization and it lost it's one free private image, so previous pushes that worked, no longer worked.



回答13:

Make sure your docker repositry name matches your local docker repo name. e.g lets say if you local repo name "kavashgar/nodjsapp"

then your should also have a repo names "kavashgar" in docker hub



回答14:

in your configuration file ~/.docker/config.json add

{
        "auths": {
             "https://index.docker.io/v1/": {
                        "auth": "XXXXXXXXXXXXX",
                        "email": "my_email@gmail.com"
                }
        }
}

where XXXXX is base64 encoding of your username:password (the : is included) of https://hub.docker.com

in my case i had the same error with a pull. the problem (under windows) was provoked by double docker running process, so a kill them all and restart one service and it works .



回答15:

There has already been good answers but I would like to mention one - You do NOT need to create a repository in advance before pushing it.

The problem for me was that I didn't set the correct username of the account I logged in to. But once the correct username is set before the image (e.g. YOURNAME/YOURIMAGE) via its tag, you can push it without creating a new repository in advance.

sudo docker tag IMAGE:VERSION USERNAME/IMAGE:VERSION
sudo docker push USERNAME/IMAGE:VERSION


回答16:

Same problem here, during pushing image:

unauthorized: authentication required

What I did:

docker login --username=yourhubusername --email=youremail@company.com

Which it printed:

--email is deprecated (but login succeeded still)

Solution: use the latest login syntax.

docker login

It will ask for both username and password interactively. Then the image push just works.

Even after using the new syntax, my ~/.docker/config.json looks like this after logged in:

{
    "auths": {
        "https://index.docker.io/v1/": {}
    },
    "credsStore": "osxkeychain"
}

So the credential is in macOS' keychain.



回答17:

I have received similar error for sudo docker push /sudo docker pull on ecr repository.This is because aws cli installed in my user(abc) and docker installed in root user.I have tried to run sudo docker push on my user(abc)

Fixed this by installed aws cli in root , configured aws using aws configure in root and run sudo docker push to ecr on root user



回答18:

My problem was an invalid Authorization token after 5 minutes. The push took more than 5 minutes because of the image size.

I've fixed it by increasing the "Authorization token duration" to 10 minutes.



标签: docker