Creating Docker Tags

Docker allows you to build, ship, and run applications in the containerized environment. In simple terms, you can run multiple applications on different machines or ports and make them communicate with each other.

As you are iterating on your application, you will need to push new Docker images to the Docker registry. A natural question arises is how to version these images. This is where Docker tags come into the picture. Docker tags consist of three parts: the first part is namespace, the second part is image name, and the last part is where you specify the version.

By default, the Docker image name is made from slash-separated name components. Docker tags allow you to tag the images for clarification. In simple words, Docker tags include very useful information, such as OS version. This plays a very important role in the development lifecycle, as developers use these tags to differentiate the build version.

There are two types of tags: stable tags and unique tags.

Stable Tags

A stable tag is a tag that can be used and reused for maintaining the base image of your container. You should avoid stable tags for deployments because it continues to receive updates over time. There are two sets of stable tags: the major and the minor version:

  • :1 – Specifies the major version.
  • :1.0 – Also specifies stable tags for version 1.0
  • :latest – Specifies the latest version of stable tags.

Unique Tags

It is recommended to use unique tags for deployments where you want to scale on multiple nodes. In simple terms, every image pushed to a Docker registry has a unique tag. You can use several patterns to generate unique tags, including Date-time stamp, Git commit, Manifest digest, and Build ID.

This tutorial shows you what Docker tags are and how to use them.

Requirements

  • A server running Linux with Docker installed.
  • A root password configured in your server.

Getting Started

Before starting, confirm that Docker is installed by running the following command:

docker info

You should get all the information about Docker from this command, as shown in the following output:

Client:
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 1
 Server Version: 19.03.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.4.0-29-generic
 Operating System: Ubuntu 20.04 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.844GiB
 Name: ubuntu2004
 ID: O35R:5XCI:WZGN:XUYI:IVKN:3QXX:KHMF:U4GT:KT2Y:6PWW:UURQ:HTEF
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Docker Tag Syntax

The basic syntax of Docker tags is shown below:

docker tag "image id" image/tag

Above, the term “image id” is the 12-character identification string of the image, and “tag” specifies the newly created versioning tag.

You can pull a specific version of an Ubuntu image from the Docker Hub registry using the image tag.

For example, to pull the Ubuntu 18.04 image from the Docker Hub, run the following command:

docker pull ubuntu:18.04

This command will search all images in the Docker Hub registry and download the image with the tag 18.04, as shown below:

18.04: Pulling from library/ubuntu
f08d8e2a3ba1: Pull complete
3baa9cb2483b: Pull complete
94e5ff4c0b15: Pull complete
1860925334f9: Pull complete
Digest: sha256:05a58ded9a2c792598e8f4aa8ffe300318eac6f294bf4f49a7abae7544918592
Status: Downloaded newer image for ubuntu:18.04
docker.io/library/ubuntu:18.04

Here, 18.04 is the tag of an Ubuntu image.

If you do not provide any tag, then the latest version of Ubuntu will be downloaded.

How to Tag an Image

First, list all available images in your Docker host system using the following command:

docker images

You should see the following output after entering the above command:

REPOSITORY    TAG     IMAGE ID      CREATED       SIZE
ubuntu       18.04  6526a1858e5d  3 weeks ago    64.2MB

In the above output, you should see the Ubuntu image with the id 6526a1858e5d.

Tag the Ubuntu image with the name nginx using the following command:

docker tag 6526a1858e5d ubuntu/nginx

Now, you can list your newly tagged image with the following command:

docker images

You should see your tagged image in the following output:

REPOSITORY    TAG     IMAGE ID      CREATED    SIZE
ubuntu       18.04  6526a1858e5d  3 weeks ago 64.2MB
ubuntu/nginx latest 6526a1858e5d  3 weeks ago 64.2MB

If you tag an image without specifying a tag, then it is given the latest tag by default.

Conclusion

As you have seen, Docker tags are very useful in the development lifecycle, allowing you to manage and maintain the version of your application. I hope you now have enough understanding of Docker tags.



from Linux Hint https://ift.tt/2SphFD6

Post a Comment

0 Comments