Docker build tag repository name

守給你的承諾、 提交于 2019-12-05 22:44:00

问题


One can easily build docker images through docker build command.

What I'm wondering is the t flag that you can give when building the image. For example:

$ docker build -t ouruser/sinatra:v2 .

According to documentation, the t flag is for tagging and naming purposes. Name is the part before ':', and tag is the part after it. So in our example, the name is ouruser/sinatra, and the tag is v2.

I thought this would be the image name and tag. But apparently, the name is actually some repository name? Why do I think it is? Well, because if you would after this list the images with command:

docker images

You would get a listing like this:

REPOSITORY          TAG     IMAGE ID      CREATED        SIZE
ouruser/sinatra     latest  5db5f8471261  11 hours ago   446.7 M

Bang! Major shock! You thought you were creating an image with name, and instead, you specified some repository! Related to this, I have some questions:

  1. Where is this repository located?
  2. Can I name the image without creating a repository?
  3. Where and how is this repository used, or could be used?
  4. Where can I find more information about this repository? I only found this, and it doesn't tell much to be honest: docker build docs
  5. Why is it common to use names that consist of two parts like this: somename/someothername?

Thank you for your help!


回答1:


I believe the confusion here is the word "repository." In Docker, a repository is any group of builds of an image with the same name, and potentially multiple tags. A "registry" server, like hub.docker.com or your own private registry, holds multiple repositories, e.g. the redis repository on the public registry. That one repository has multiple tags for different versions of the build.

So with that background, to answer your questions:

  1. ouruser/sinatra is located on your local Docker host until you do a docker push
  2. No, the repository and the tag is the name of the image.
  3. While local on your system, you can use this image locally. Once you push it up to a registry, you can then pull it down to any other Docker host that has access to that registry. And if you do a docker save you can save that image for a docker load on another host.
  4. I'm sure there is documentation covering this somewhere on docs.docker.com, but I learned from a class.
  5. The username/imagebase format came about to support pushing to your own namespace in hub.docker.com. Without that, whoever makes the first "Redis" image calls it "redis" while the next person makes their own repository called "redis-improved", and we quickly get into a jumble of confusing names where it's not clear who made what and what is a reputable image. That naming isn't required for images you make locally, but is still encouraged since images you pull from hub.docker.com may lack a username if they are maintained by Docker themselves. Without your username, you won't know which images you pulled down and which you built yourself.


来源:https://stackoverflow.com/questions/37815524/docker-build-tag-repository-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!