简体   繁体   中英

Pushing images to docker hub

I do not really understand the dockerhub yet. I got the following case:

  • I tag several images for the hub

docker tag myimageA myuser/myrepo:1

docker tag myimageB myuser/myrepo:1

docker tag myimageC myuser/myrepo:1

Afterwards I push them with docker push myuser/myrepo

Now, when deleting all my local images and pulling my own docker repo again there will be only one entry when I execute docker images :

myuser/myrepo

I expected to be able to push single images to docker hub. Beside that, I can only view the tag I pushed (latest, 1 or whatever).

Question: will docker push push all images tagged for the repo namespace? Or is there a way to push single images to a repo and pull them one by one?

Only one image has a given tag/label at a time. When you ran docker tag myimageC myuser/myrepo , image B lost the tag, and the docker push only pushed the single most-recently-tagged image. If you gave a different image that tag, and pushed it, it would replace whatever was previously on Docker Hub with what you pushed.

If these images are really different, best practice would be to push them as separate names, eg , myuser/myimageC . Also don't forget the "tag" part of the image name; it's common to tag an image with a version number or build details (if you build both Alpine and Ubuntu-based images of the same thing, for example), and in many environments the default ...:latest tag being a moving target presents a problem.

I remember my first steps in docker and clearly remember this small struggle as well.

When you creates an image:

docker build -t <docker_hub_user_name>/<image_name>:<tag_name> /path/to/dockerfile

That image is registered with the tag you has assigned. Otherwhie you can build the image without the -t option and that would make an image with a random id that later on can be retagged.

If you taggs the image:

docker tag myimageA myuser/myrepo:1

docker tag myimageB myuser/myrepo:1

docker tag myimageC myuser/myrepo:1

Docker tag works like:

"docker tag" requires exactly 2 arguments.
See 'docker tag --help'.
Usage:  docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

So you are mainly using diferent images to tag the same image. Or what is the same you are naming three diferent images into a single one. You are overwriting three diferent images into myuser/myrepo:1.

Docker hub uses < myuser >/myrepo:1 to store the root of your image into your account but in other cases this segment is used to identify your respository host. myuser/< myrepo >:1 it is the name of your image, so if you are using your aplication A, B or C, the name of the image shoud be diferent and myuser/myrepo:< 1 > the last element should if it be used for versioning the same image. It is commondly used to versionate it and there are some tags that are used as default like: last . If you uses this word docker will use the latest image able of this docker image.

So answering you question:

Question: will docker push push all images tagged for the repo namespace? Or is there a way to push single images to a repo and pull them one by one?

You must push every image independly to your docker hub account or into your docker registry server. Althought you could use a pipe comand to push all your docker images with one sentence. There is no way to push all of your local at once with a single docker command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM