Docker: How to authenticate for docker push?
Asked Answered
E

9

85

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?

Encourage answered 23/12, 2015 at 11:3 Comment(0)
S
78

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 protected]
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
Suribachi answered 23/12, 2015 at 11:24 Comment(5)
But how does a person use something like CJE to push the built image to the registry in the Jenkinsfile if you can't inline specify both the username and password to run a login in the terminal?Jidda
The login step shown here is manual and requires an interactive terminal and someone typing the password. One way to automate that would be seveibar's answer, another would be to use the same command here with --password-stdin - like so: docker login --username=<user> --password-stdin <<<'password'Biochemistry
--email is no longer valid for the docker CLILikelihood
worked for me without email docker login --username=maryatdockerMisstep
email flag does not work anymore. maybe i shouldn't dig around in almost 10 year old posts.Col
B
58

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.

Bootie answered 25/7, 2016 at 14:15 Comment(1)
never put your password in the command line like thatVial
H
12

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

docker login -u ${USERNAME} -p ${PASSWORD} ${DOCKER_REPOSITORY}
Henshaw answered 12/8, 2021 at 19:11 Comment(0)
B
12

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.

Barcroft answered 2/5, 2022 at 10:33 Comment(0)
G
8

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.

Gustafsson answered 23/12, 2015 at 11:25 Comment(0)
M
2

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

Myogenic answered 31/8, 2021 at 8:0 Comment(0)
B
1

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.

Bangs answered 8/12, 2021 at 6:32 Comment(0)
S
0

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
Stalag answered 29/1, 2022 at 18:6 Comment(0)
G
-1

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.

Goldfarb answered 7/3, 2022 at 17:34 Comment(3)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewDowable
This helped me to resolve the " Error response from daemon: Head ...unknown: Bad credentials" where I was login to Docker without sudo but attempted to pull images with sudo. So, both logging and pull have to be done with a similar privilegeRegular
Glad to be of assistance. If "They" had there way they'd have removed my comment. As per the above. "This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review – Juan Fontes Mar 12 at 10:46"Goldfarb

© 2022 - 2024 — McMap. All rights reserved.