Docker images use version control registers, such as the Docker Hub, which hosts public images for everyone to download and run. But before uploading an image to the hub or any registry, you need to give it the right tags.
Container against image
It is important to understand the difference between containers and images before talking about tags, as they are often used quite interchangeably and this can lead to some confusion.
A Docker image is what you get from driving
docker build with your Docker file. It consists of several layers to optimize disk and memory usage. An image is read-only.
A Docker container is an example of an image that the processes actually run in. It is a read / write file system, so basically an image is a template that you use to create multiple containers from. It contains the base code and everything the app needs to get started. The containers are initialized with the image when they are created, then they can change the file system as they wish.
Pictures are what you print to the container register. Then you can on your servers refer to the image in the register to download the container.
Tags Track versions of embedded images
When you drive one
docker build, you create a new image with a unique ID, such as “38054d5e8a27.”
Tags are simply labels that provide a better way to handle version control and releases. They are like labels that you can assign to any completed building. Instead of referring to the building ID, you can tag an image with a label in the format major.minor.patch and easily be able to tell which image is, or which format your organization prefers.
It’s pretty easy to notice. You can use
docker tag to do it after the fact, but it is much easier to do it when you build using
docker build -t repository/image:tag .
This builds the image from Dockerfile and tags it with the tag you specified. The tag is
[:TAG] part, after semicolon, although Docker will say “
Successfully tagged repository/image:tag“. The
repository/image part is just the name of the image, and if you plan to drive to an archive, you need to tag it in
For Docker Hub, the driver name is just your username, so the command looks like:
docker build -t anthonyheddings/nginx:tag .
If you do not specify a specific tag, Docker automatically marks it as “recent.”
Another common practice is to tag the image with git commit ID and thereby link the version control to the built-in images. You can automate this quite easily with
docker build -t vicerust/core:$(git rev-parse --verify HEAD) .
Once an image has been tagged, you can drag it to the registry with
docker push, passes in
docker push repository/image
From there, you have access to it in
docker run as usual. If you do not specify a tag,
docker run uses automatically
Latest does not always mean “latest”
"Latest" the tag is a bit confusing. Despite how the name sounds, it does not always point to the latest version. It is simply a special tag that is assigned automatically when you do not enter a tag. This has the effect of avoiding tags completely and only clicking on a “latest” version.
You can use the most recent tag either by simply not specifying a specific tag:
docker build -t repository/image .
Or by manually tagging an image as
docker build -t repository/image:latest .
which works well if you only use the last tag. But if you also want to use version ID tags, you have to double-encode your images each time, which can mean that “latest” does not always mean the last built image. It is good to avoid using
latest along with other tags to prevent this confusion. Release only your tags, each time, either with manual correction numbers or with git commit ID.