Docker: How to authenticate for docker push?

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?

9 Answers

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

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

$ docker login --username=maryatdocker --email= 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 
2

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.

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.

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

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

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.

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.

docker login --username=YOUR_DOCKERHUB_USERNAME

enter image description here

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

Refer:

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 Login Succeeded 

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.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like