I can't push my docker image to my docker hub repository.
I am logged in. The repo exists and is public. I tried multipled ways of building/tagging/pushing my image.
docker login -u username -p password
docker build ./ -t my-image -f devops/Dockerfile
docker tag image username/my-image
docker push username/my-image
I crawled tens of questions on multiple websites. The answers were always either how to login correctly or how to tag and push the image. It seems to me like I am doing both correctly, so what's wrong?
Did you login with with your docker command ? something like this
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
I guess you need to set the :latest tag on your image. And try to push it with the :latest tag. Also make a correct naming of the container.
Note that only a-z0-9-_. are allowed when naming images:
docker tag myImage myusername/myimage:latest
docker push myusername/myimage:latest
I did it this way and it worked for me.
Here is my example bash script for automate the image taging after a successful build and push it to the docker hub.
#!/bin/bash
docker build -t myusername/myimage:latest .
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push myusername/myimage:latest
docker tag myusername/myimage:latest myusername/myimage:1
docker push myusername/myimage:1
docker tag myusername/myImage:latest myusername/myimage:1.1
docker push myusername/myImage:1.1
docker tag myusername/myimage:latest myusername/myimage:1.1.1
docker push myusername/myimage:1.1.1
I usually only write
docker login
which then requests that you enter your details or says that it's using your existing details that have been saved in the system. Otherwise, I can't see any problems with your commands.
I'm not sure that just writing docker login will make any difference but can't see any other differences.
Related
I have a git repository from where I am trying to build and publish a docker image to docker hub.
Some how I am keep on getting Unauthorised for docker login step.
Any Help is appreciated.
GitHub Repo : https://github.com/Git-Beginner/ghaction/actions
You should first login to docker hub by typing the command docker login it will prompt the user name and after that password of docker hub after that try pushing the image again to docker hub
I am not that sure if this is what you have asked for but in order to push images to docker hub , first you need to build your docker image. then create a repository on docker hub with the name you want. and then do something like this
docker build -f ./Dockerfile -t nametoyourlocalimage:version . //this will build your docker image locally
docker tag nametoyourlocalimage:version YourDockerHubNewReporUrlYouJUstCreated
docker login //this will prompt you to enter your username and password
docker push YourDockerHubNewRepoUrlYouJUstCreated
docker logout
I want to create my own image and push it into my docker-hub.
Prepare:
mkdir /tmp/mydebian
cd /tmp/mydebian
vim mydebian.Dockerfile
#all contents omitted here
Build the image with Dockerfile:
docker build -f mydebian.Dockerfile --tag=mydebian:0.0.1 .
Check it:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mydebian 0.0.1 bd66705654b1 5 minutes ago 460MB
Login docker:
docker login -u "myusername" -p "xxxxxxxx" docker.io
Push now:
docker push myusername/mydebian:0.0.1
The push refers to repository [docker.io/myusername/mydebian]
An image does not exist locally with the tag: myusername/mydebian
Try other format:
docker push mydebian:0.0.1
The push refers to repository [docker.io/library/mydebian]
690c901c038e: Preparing
1155352a0b68: Preparing
1201adb8bea9: Preparing
a13c519c6361: Preparing
denied: requested access to the resource is denied
How can fix it?
You need to tag your images with the name they'll be pushed with. Either on build:
docker build -f mydebian.Dockerfile --tag=myusername/mydebian:0.0.1 .
Or to give an existing image an additional tag:
docker tag mydebian:0.0.1 myusername/mydebian:0.0.1
Leave out the docker.io in the end for the login command. Like this:
docker login -u "myusername" -p "xxxxxxxx"
Same error with a longer description
I wrote gitlab-ci.yml file.
I Login to gitlab registry with this command
docker login -u $CI_DEPLOY_USER -p $CI_DEPLOY_PASSWORD $CI_REGISTRY
and in the next step build the docker image
docker build -t $REGISTRY .
But When i push docker image
docker push $REGISTRY
I get this error
denied: requested access to the resource is denied
How can fix this error?
Gitlab is probably not finding any repository of the same name as the registry you're trying to push to.
For example if you do docker push gitlab.helloworld.com/prefix/repo-name, then you need to have a project prefix/repo-name
You can read about more about this issue here
tag the image with {{username}}/{{imagename}}:{{version}}
docker login
docker push {{username}}/{{imagename}}:{{version}}
I'm migrating a project from a private registry to hub.docker.com but I don't have all tagged image on computer.
I have access to the registry machine via SSH.
Question
How can I push all my registry images to hub.docker.com?
I think that the only way is to pull them all, then retag them and push to hub.docker.com
You can script it with something like:
for repository in $(curl -s http://localhost:5000/v2/_catalog | jq -r '.repositories[]'); do
for image in $(curl -s http://localhost:5000/v2/${repository}/tags/list | jq -r '(.name + ":" + .tags[])')
docker image pull localhost:5000/${image}
docker image tag localhost:5000/${image} <YOUR_HUB_PREFIX>/${image}
docker image push <YOUR_HUB_PREFIX>/${image}
# if you need some cleanup
docker image rm localhost:5000/${image} <YOUR_HUB_PREFIX>/${image}
done
done
Access to your registry machine via SSH, use docker login to login inside your Docker Hub account, add a tag to your images which points to Docker Hub docker tag my_own_registry.com/image:tag user/image:tag a then push that new tag using docker push user/image:tag.
#zigarn script automates this job.
Edit: You commented that your bandwith is bad, then you can access via ssh to your registry machine, save your image using docker save, then copy it to your machine and load it by docker load and finally push it to Docker Hub as explained above.
I have a GKE cluster running in GCE, I was able to build + tag an image derived from ubuntu:16.04:
/ # docker images
REPOSITORY TAG IMAGE ID
CREATED SIZE
eu.gcr.io/my-project/ubuntu-gcloud latest a723e43228ae 7 minutes ago 347MB
ubuntu 16.04 ebcd9d4fca80 7 days ago 118MB
First I try to log in to registry (as documented in GKE docs)
docker login -u oauth2accesstoken -p `curl -s "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token" -H "Metadata-Flavor: Google"|awk -F\" "{ print \$4 }"` eu.gcr.io`
And then the docker push command fails:
# docker push eu.gcr.io/my-project/ubuntu-gcloud
The push refers to a repository [eu.gcr.io/my-project/ubuntu-gcloud]
a3a6893ab23f: Preparing
6e390fa7d62c: Preparing
22b8fccbaf84: Preparing
085eeae7a10b: Preparing
b29983dd2306: Preparing
33f1a94ed7fc: Waiting
b27287a6dbce: Waiting
47c2386f248c: Waiting
2be95f0d8a0c: Waiting
2df9b8def18a: Waiting
denied: Unable to create the repository, please check that you have access to do so.
The token should be valid, in another instance I'm able to gcloud whatever with it; the service account has 'Editor' role on the project.
The weirdest part is when I do docker login with obviously invalid credentials
misko#MacBook ~ $ docker login -u oauth2accesstoken -p somethingverystupidthatisreallynotmypasswordortoken123 eu.gcr.io
Login Succeeded
login always succeeds.
What shall I do to successfully docker push to gcr.io?
Try this:
gcloud docker -- push eu.gcr.io/my-project/ubuntu-gcloud
If you want to use regular docker commands, update your docker configuration with GCR credentials:
gcloud docker -a
Then you can build and push docker images like this:
docker build -t eu.gcr.io/my-project/ubuntu-gcloud .
docker push eu.gcr.io/my-project/ubuntu-gcloud