Why can't I push local Docker image to Docker Hub repo? - docker

I have Docker ID, let's say -> KN, and created a private repo. I can log into Docker Hub via CLI too. I run a container based on a image & commit that container to an image with following command
docker commit ub18 reponame/ub18 ==> successfull
but when I push that image like following, it doesn't upload.
Output of Docker images shows this image on top.
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
standard/ub18 latest c8ebc0f1dd75 12 seconds ago 102MB
docker push reponame/ub18 ==> gives error
The push refers to repository [docker.io/standard/ub18]
7660ded5319c: Preparing
94e5c4ea5da6: Preparing
5d74a98c48bc: Preparing
604cbde1a4c8: Preparing
denied: requested access to the resource is denied

So to push your images to your Docker Hub repo first you have to login to Docker Hub repo using username and password:
docker login
Then perform tagging of your image properly :
docker tag image_id yourhubusername/reponame:tag
Your image tag has to be in this specific format.
Then to push :
docker push yourhubusername/reponame:tag
assuming you are logged in.
If you want to gain more information about it, refer to docker docs.

Related

How to push a docker image that has a tag different from docker hub repository?

Let's say I have an account on docker hub and my username is hub_user.
I create a repository called react-dev on it.
Now on my machine, I have created an image tagged company/react/dev.
I can see it using docker image ls:
REPOSITORY TAG IMAGE ID CREATED SIZE
company/react/dev latest f344922a299e 7 minutes ago 368MB
Now I'm stuck at pushig this image into that hub repository.
This command does not work:
docker push company/react/dev
Using default tag: latest
The push refers to repository [docker.io/company/react/dev]
f63cd7f19f75: Preparing
e8aee5ec6588: Preparing
48ee8f528027: Preparing
f3abd083ca1f: Preparing
d02e39b7f91a: Preparing
0586d9cce1ac: Waiting
48286fbe1b87: Waiting
f22adfb1c0f3: Waiting
9a5d14f9f550: Waiting
denied: requested access to the resource is denied
What should I do?
You will have to use hub_user/react-dev when push.
For your scenario, you could use docker tag to create a tag TARGET_IMAGE that refers to SOURCE_IMAGE, see this.
Then, something like next could work:
$ docker tag company/react/dev hub_user/react-dev
$ docker push hub_user/react-dev
Well the tag and push should follow the convention like this while pushing to dockerhub.
dockerhub_username/repo_name:$TAG
so when building/tagging image it should be like this
docker build -t hub_user/react-dev:latest
Then push the same image
docker push hub_user/react-dev:latest

How to load updated docker image onto other machine

I have 2 hosts running the same docker customized image. I have modified the image on host 1 and saved the image to a custom.tar. If I take that image and load it onto host 2 will it just update or should I remove the old docker image first?
There are 2 ways to do that with repository and without repository using load and save.
With repository below are the steps.
Log in on Docker Hub
Click on Create Repository.
Choose a name and a description for your repository and click
Create.
Log into the Docker Hub from the command line
docker login --username=yourhubusername --email=youremail#company.com
tag your image
docker tag <existing-image> <hub-user>/<repo-name>[:<tag>]
Push your image to the repository you created
docker push <hub-user>/<repo-name>:<tag>
Pull the image to host 2
docker pull <hub-user>/<repo-name>:<tag>
This will add the image to docker hub and available on internet and now you can pull this image to any system.
With this approach you can keep the same images with different tags on system. But if you don't need old images better to delete that to avoid junk.
Without docker hub.
This command will create tar bundle.
docker save [OPTIONS] IMAGE [IMAGE...]
example: docker save busybox > busybox.tar
Load an image from a tar archive or STDIN
docker load [OPTIONS]
example:docker load < busybox.tar.gz
Recommended: Docker hub or DTR approach easy to manage unless you have bandwidth issue in case your file is large.
Refer:
Docker Hub Repositories

Docker push local image under specified tag name

I need to push Docker image from my local machine to my https://hub.docker.com repository under the specified tag name.
Locally I have the following image:
REPOSITORY TAG IMAGE ID CREATED SIZE
repo1/private image1 29234rs8dsf 5 months ago 1.07GB
Hot to push this image under the specified tag(not latest, for example, testtag1) under my https://hub.docker.com repository inttest/myimage ?
If i understood the question correctly, you can do it with following 3 steps -
TAG your local image to dockerhub repo image -
$ docker tag repo1/private:image1 inttest/myimage:testtag1
Login to your dockerhub account using docker login
Push your dockerhub repo tagged image -
$ docker push inttest/myimage:testtag1

docker push doesn't use the correct repository and fails

I'm trying to push a docker image to an Azure container repository and even after successfully "logging in" the push command tries to push it to docker.io and then fails.
Note: I am using Windows 10 Pro and have set up docker to to use the minikube docker dameon
How do I tell docker push to use my Azure container repo?
See the output:
You must tag your image with the Docker Registry URL and then push like this:
docker tag design-service dockerregistry.azurecr.io/design-service
docker push dockerregistry.azurecr.io/design-service
Note: The correct term is registry and not repository. A Docker registry holds repositories of tagged images.

Awaiting gcloud docker -- push

Im building a deployment script in nodejs, with 1 part being calling the gcloud cli through require('child_process').spawn(...); to push the already build docker images. i execute the following command:
gcloud docker -- push myImage
This all works great, the images gets uploaded. But the problem is that gcloud docker opens a new process to push my image and the process i spawned, closes before the pushing of the image is done.
Problem is, I want to delete the builded images locally, directly afterwards.
I've been looking in the gcloud docker documentation but i don't see any argument for this.
Is there a way to know that the process of uploading the images was completed?
edit:
i did find a way to do it only through docker but i'd like a universal solution (both working on windows and linux environments)
After some more research on the google documentation, i found this authentication page
They tell you to create a service account and use the json private key you get as token to use into docker login. This way you don't need an oauth token for your automated services, but you can use this json key instead.
You can check all the images by running this command:
[sudo docker images]
Take a note of the "IMAGE ID" it will used when Tagging and deleting the image.
When you build a docker images, tag it before By running this command:
[docker tag "IMAGE ID" gcr.io/{the Google Container Registry path}:{version} ]
You can push any built image by running this command:
[gcloud docker -- push gcr.io/{the google container registry path}:{version}].
When pushing you will notice that list of container are pushed to your Google Container registry see the example below:
$ sudo gcloud docker -- push gcr.io/{the google container registry path}:{version}
The push refers to repository [gcr.io/{the google container registry path}]
43d35f91f441: =================> Pushed
3b93beb428bf: Layer already exists
629fa6a1373d: =================> Pushed
0f82335d5733: Layer already exists
c216b39a9ab6: Layer already exists
ccbd0c2af699: Layer already exists
38788b6810d3: Layer already exists
cd7100a72410: Layer already exists
v1: digest: sha256:**************************************************************** size: 1992
You can check all the images by running this command:
[sudo docker images]
Take a note of the "IMAGE ID" of the image you need to delete.
Run the command :
[sudo docker rmi "IMAGE ID"].
If the image doesn't allow to be deleted, you have to stop the container that is still running and prune the docker
[sudo docker container stop "the container ID"]
[sudo docker container prune]
Then you can delete the image.

Resources