Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker build tag repository name

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!

like image 592
Ville Miekk-oja Avatar asked Jun 14 '16 14:06

Ville Miekk-oja


People also ask

How do I name a docker repository?

The repository name needs to be unique in that namespace, can be two to 255 characters, and can only contain lowercase letters, numbers, hyphens ( - ), and underscores ( _ ). Note: You can't rename a Docker Hub repository once it's created. The description can be up to 100 characters and used in the search result.

How do I create a docker image with a tag name?

To give tag to a docker file during build command: docker build -t image_name:tag_name . otherwise it will give latest tag to you image automatically.

How do I specify a Dockerfile tag?

To specify a value for repository and tag of the image, we use the --tag or -t flag with the $ docker build command. The format of the value for this flag is <repository>:<tag> . If we leave the :<tag> part out, Docker will use the latest value for the <tag> part implicitly.

How do I create a Docker Hub repository?

From the Docker Hub dashboard, click Create Repository. Fill out the repository details (be sure to set the Visibility drop-down to either public or private), then click Create. On the next page you will find details about your new repository, including the docker pull command for your images.


1 Answers

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.
like image 149
BMitch Avatar answered Oct 17 '22 09:10

BMitch