How to push image from private registry to hub.docker.com? - docker

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.

Related

Build and Push Docker Image to Docker Hub- UnAuthorised

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

Can't build docker image: "requested access to the resource is denied"

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.

How do I push a Docker Image in Virtual Box to Google repository?

I have a virtualbox development:
$docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
development - virtualbox Running tcp://*.*.*.*:**** v18.05.0-ce
Inside development I have this:
$docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
busybox latest e1ddd7948a1c 1 day ago 1.16MB
pritam/play-docker latest 34eb2664f14e 1 day ago 1.4GB
Now I want to push this image inside virtual box to google repository. How do I that?
you can use docker push command
docker push imageTagName
http://docs.docker.com/engine/reference/commandline/push
For your own registry you can use
docker push registry.example.com/image
http://blog.docker.com/2013/07/how-to-use-your-own-registry.
And for google container registry reference:
http://cloud.google.com/container-registry/docs/pushing-and-pulling
docker [push/pull] gcr.io/{PROJECT_ID}/{image}:tag
for authentication you can check google container registry reference
https://medium.com/google-cloud/using-googles-private-container-registry-with-docker-1b470cf3f50a
after you get google auth keys as json format (key.json)
docker login -u _json_key -p “$(cat key.json)”
after login success you can push your image
docker push gcr.io/project_id/imageName:tag

Access denied when pulling Docker image from a repository I own

I built a Docker image that I pushed to Docker Hub under my account and removed locally after. But when I try to pull it, it throws the following error:
Error response from daemon: pull access denied for mightyspaj/dockerfile-assignment-1, repository does not exist or may require 'docker login'
I'm logged into the same account that owns the repository for this image and can perform other tasks (such as pushing) perfectly fine. The repository also definitely exists on Docker Hub, yet it fails when I try to pull it.
I've tried the following things:
Logging out of my account and back in again
Renaming config.json and regenerating it
Running an isolated Docker container with docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock:ro docker sh, then logging into my account and attempting to pull the image
Deleting and recreating the repository
All of these things still produce the same error. I'm baffled.
To note, both my client and engine versions are 17.12.0-ce. My OS is Ubuntu 17.10 (64-bit).
Console output
docker login
-> % docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: mightyspaj
Password:
Login Succeeded
docker tag
-> % docker tag dockerfile-assignment-1:latest mightyspaj/dockerfile-assignment-1
docker push
-> % docker push mightyspaj/dockerfile-assignment-1
The push refers to repository [docker.io/mightyspaj/dockerfile-assignment-1]
8427a8e6a29f: Pushed
655a921743e8: Pushed
8aa44edb7524: Pushed
60f1a2dc4cd8: Mounted from library/node
9185fe936b87: Mounted from library/node
e53f74215d12: Mounted from library/node
latest: digest: sha256:6c68220ba84f13d0229ef4458f22369410bb98764b908a75be0849c3003de160 size: 1582
docker image rm
-> % docker image rm mightyspaj/dockerfile-assignment-1
Untagged: mightyspaj/dockerfile-assignment-1:latest
Untagged: mightyspaj/dockerfile-assignment-1#sha256:6c68220ba84f13d0229ef4458f22369410bb98764b908a75be0849c3003de160
docker image pull
-> % docker image pull mightyspaj/dockerfile-assignment-1
Using default tag: latest
Error response from daemon: pull access denied for mightyspaj/dockerfile-assignment-1, repository does not exist or may require 'docker login'
I could fix the same issue only when I made the repository public. Make sure the repository is public then this is the set of instructions I followed in command line:
Once logout from docker hub and login again.
1- docker logout
2- docker login --username=YOURUSERNAME
Enter password when asked
3- docker pull repositoryName"/"imageName[:tag]
if "tag" is not included the default value will be "latest".
Then check the images by docker images command to check if its been pulled.
After pulling is done I made the repository private again.
This solution is only valid on private docker repositories!!
First try to login on your private repo e.g:
docker login dockerrepo.example.com
Then
If you build new image with dockerfile based on image in your private repository then you must prefix your base image with private repository url:
FROM PRIVATE_REPO_URL + IMAGE_INFO
sample:
PRIVATE_REPO_URL --> dockerrepo.example.com
BASE_IMAGE --> samples/java/jdk:1.6
Your dockerfile look like this:
FROM dockerrepo.example.com/samples/java/jdk:1.6

Docker private registry with mirror

I created two Docker containers. The first one provides a private Docker registry and the second one is a mirror of the official Docker registry:
docker run -d --name registry -v /local/path/to/registry:/registry -e SETTINGS_FLAVOR=local -e STORAGE_PATH=/registry -p 5000:5000 registry
docker run -d --name mirror -v /local/path/to/mirror:/registry -e STORAGE_PATH=/registry -e STANDALONE=false -e MIRROR_SOURCE=https:/registry-1.docker.io -e MIRROR_SOURCE_INDEX=https://index.docker.io -p 5555:5000 registry
Now I would like to combine both. Whenever a user pulls images it should first query the private registry and then the mirror. And when images are pushed they should only be pushed to the private registry.
I do not have an idea about how this can be done. Any help is appreciated.
You cannot just force all docker push commands to push to your private registry. One reason is that you can have any number of those registers. You have to first tell docker where to push by tagging the image (see lower).
Here is how you can setup docker hosts to work with a running private registry and local mirror.
Client set-up
Lets assume that you are running both mirror and private registry on (resolvable) host called dockerstore. Mirror on port 5555, registry on 5000.
Then on client machine(s) you should pass extra options to docker daemon startup. In your case:
Add --registry-mirror=http://dockerstore:5555 to tell daemon to prefer using local mirror rather then dockerhub. source
Add --insecure-registry dockerstore:5000 to access the private registry without further configuration. See this answer
Restart docker daemon
Using the mirror
When you pull any image the first source will be the local mirror. You can confirm by running a docker pull, e.g.
docker pull debian
In the output there will be message that image is being pulled from your mirror - dockerstore:5000
Using local registry
In order to push to private registry first you have to tag the image to be pushed with full name of the registry. Make sure that you have a dot or colon in the first part of the tag, to tell docker that image should be pushed to private registry.
Docker looks for either a “.” (domain separator) or “:” (port separator) to learn that the first part of the repository name is a location and not a user name.
Example:
Tag 30d39e59ffe2 image as dockerstore:5000/myapp:stable
docker tag 30d39e59ffe2 dockerstore:5000/myapp:stable
Push it to private registry
docker push dockerstore:5000/myapp:stable
Then you can pull as well
docker pull dockerstore:5000/myapp:stable
If not present, create the file:
sudo nano /etc/docker/daemon.json
Then paste the following:
{
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com"
]
}
Then retart Docker daemon
$ sudo systemctl restart docker
[Source]
Just to be clear, docker documentation confirms that:
It’s currently not possible to mirror another private registry. Only
the central Hub can be mirrored.
Repository names are intended to be global, that is the repository redis always refers to the official Redis image from the Docker Hub. If you want to use a private registry, you prefix the repository name with the name of the registry e.g. localhost.localdomain:5000/myimage:mytag.
So when you pull or push, it will automatically go to the relevant registry. The mirror should be easy to set up, you just pass the URL to the daemon with the --registry-mirror= argument.
This isn't perfect for enterprise users, hence this (closed) Docker issue.

Resources