Docker: How to authenticate for docker push?

DockerDocker Registry

Docker Problem Overview


Hi i'm trying docker push

[docker-simple-httpserver]# docker push myregistry/simplehttpserver:latest
The push refers to a repository [myregistry/simplehttpserver] (len: 1)
Sending image list
FATA[0000] Error: Status 403 trying to push repository simplehttpserver: "{\"error\": \"Unauthorized updating repository images\"}" 

is there a way for me to specify the username and password on docker push command?

Docker Solutions


Solution 1 - Docker

I would think they keep passwords off the command line for security reasons.

The way to do it is to login first then push.

https://docs.docker.com/mac/step_six/

$ docker login --username=maryatdocker --email=mary@docker.com
Password:
WARNING: login credentials saved in C:\Users\sven\.docker\config.json
Login Succeeded

Then push

$ docker push maryatdocker/docker-whale
The push refers to a repository [maryatdocker/docker-whale] (len: 1)
7d9495d03763: Image already exists
c81071adeeb5: Image successfully pushed

Solution 2 - Docker

Typically you would specify your password using the interactive docker login then do a docker push.

For a non-interactive login, you can use the -u and -p flags:

docker login -u="${DOCKER_USERNAME}" -p="${DOCKER_PASSWORD}"

The Travis CI docs for docker builds gives an example of how to automate a docker login.

See docker login for more details.

Solution 3 - Docker

As far as I know you have to use docker login. The credentials will be stored in /home/user/.docker/config.json for following docker pushes.

If you are after automation the command expect will be interesting for you.

Solution 4 - Docker

If you are tagging image with IP then login docker registry with IP, If you are tagging image with domain-name then login docker with domain-name, Somehow docker doesn't like mixing IP and domain and failing.

Solution 5 - Docker

In case, one needs to login to the custom docker repo, use below:

docker login -u ${USERNAME} -p ${PASSWORD} ${DOCKER_REPOSITORY}

Solution 6 - Docker

docker login --username=YOUR_DOCKERHUB_USERNAME

enter image description here

In this case your dockerhub password will be an access token.

Refer: https://docs.docker.com/docker-hub/access-tokens/#create-an-access-token

Solution 7 - Docker

Not direct answer to the question, but you can first login and then do docker push.

docker login -unice-username

After which it will prompt for a password. After successful login you can do docker push.

WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

Solution 8 - Docker

use "sudo docker login" not "docker login" as one uses the root account and the other uses your personal.

Personally I create the repo on dockers website prior to the upload.

Solution 9 - Docker

The accepted answer works perfectly fine! However, if you are trying to access a private registry, you may have to consider making the following change request.

docker login -u ${user_name} ${private_registry_domain} 

Provide password, when it prompt for the same.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJasView Question on Stackoverflow
Solution 1 - DockerKeepCalmAndCarryOnView Answer on Stackoverflow
Solution 2 - DockerseveibarView Answer on Stackoverflow
Solution 3 - DockermichaelbahrView Answer on Stackoverflow
Solution 4 - DockerKrishnaView Answer on Stackoverflow
Solution 5 - DockerKnockingHeadsView Answer on Stackoverflow
Solution 6 - DockerAnantha Raju CView Answer on Stackoverflow
Solution 7 - DockerJohnView Answer on Stackoverflow
Solution 8 - DockerMichaelView Answer on Stackoverflow
Solution 9 - DockerArun RamachandranView Answer on Stackoverflow