79

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?

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
Jas
  • 14,493
  • 27
  • 97
  • 148

9 Answers9

70

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
KeepCalmAndCarryOn
  • 8,817
  • 2
  • 32
  • 47
  • 2
    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? – cody.tv.weber Sep 21 '18 at 21:10
  • 1
    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= --password-stdin <<<'password'` – Guss Jun 24 '21 at 06:50
  • --email is no longer valid for the docker CLI – Majolo Aug 16 '23 at 13:54
52

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.

nik7
  • 806
  • 3
  • 12
  • 20
seveibar
  • 4,403
  • 4
  • 30
  • 31
10

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.

cigien
  • 57,834
  • 11
  • 73
  • 112
Arun Ramachandran
  • 1,270
  • 5
  • 23
  • 36
9

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

docker login -u ${USERNAME} -p ${PASSWORD} ${DOCKER_REPOSITORY}
KnockingHeads
  • 1,569
  • 1
  • 22
  • 42
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.

michaelbahr
  • 4,837
  • 2
  • 39
  • 75
1

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

Anantha Raju C
  • 1,780
  • 12
  • 25
  • 35
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.

Krishna
  • 501
  • 1
  • 8
  • 17
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
John
  • 180
  • 11
0

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.

Michael
  • 84
  • 4
  • 1
    This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31233917) – Juan Fontes Mar 12 '22 at 10:46
  • 1
    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 privilege – ewalel Apr 18 '22 at 10:17
  • 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" – Michael May 09 '22 at 11:12