SystemMen - How to list the tag of a container image? In the previous article, you already know what the tag of an image container is.
On the Docker Hub website, you can see all the tags easily.
But if you use the search
command, how can you list all tags of an image?
Docker registry API
If you remember, the search command in docker does not display the image tag. So what will we do?
Docker supports something called Docker registry API, you can use these APIs to get the information you need.
The idea is that you will use the API to get information about the tag of a certain image.
What is MJSON?
A little more you will understand why we use MJson. So what is it?
Mjson is a tool that helps us print json results in “better” form. In general, its purpose is to make it easier to see results.
The command list all tags of an image
The following command will help you list all tags of an image.
curl https://registry.hub.docker.com//v1/repositories/<image-name>/tags
The syntax of the command is very simple, you just need to change the name of the image before the tag section.
For example, I use the search command to list all image centos.
root@linux:~# docker search centos NAME DESCRIPTION STARS OFFICIAL AUTOMATED centos The official build of CentOS. 5325 [OK] ansible/centos7-ansible Ansible on Centos7 121 [OK] jdeathe/centos-ssh CentOS-6 6.10 x86_64 / CentOS-7 7.5.1804 x86… 107 [OK] consol/centos-xfce-vnc Centos container with "headless" VNC session… 86 [OK] imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 54 [OK] centos/mysql-57-centos7 MySQL 5.7 SQL database server 51 tutum/centos Simple CentOS docker image with SSH access 44 openshift/base-centos7 A Centos7 derived base image for Source-To-I… 43 gluster/gluster-centos Official GlusterFS Image [ CentOS-7 + Glust… 41 [OK] centos/postgresql-96-centos7 PostgreSQL is an advanced Object-Relational … 37 centos/python-35-centos7 Platform for building and running Python 3.5… 35 kinogmt/centos-ssh CentOS with SSH 26 [OK] openshift/jenkins-2-centos7 A Centos7 based Jenkins v2.x image for use w… 20 centos/php-56-centos7 Platform for building and running PHP 5.6 ap… 20 pivotaldata/centos-gpdb-dev CentOS image for GPDB development. Tag names… 10 openshift/wildfly-101-centos7 A Centos7 based WildFly v10.1 image for use … 6 openshift/jenkins-1-centos7 DEPRECATED: A Centos7 based Jenkins v1.x ima… 4 pivotaldata/centos Base centos, freshened up a little with a Do… 3 darksheer/centos Base Centos Image -- Updated hourly 3 [OK] pivotaldata/centos-mingw Using the mingw toolchain to cross-compile t… 2 blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK] pivotaldata/centos-gcc-toolchain CentOS with a toolchain, but unaffiliated wi… 1 openshift/wildfly-81-centos7 A Centos7 based WildFly v8.1 image for use w… 1 smartentry/centos centos with smartentry 0 [OK] pivotaldata/gpdb6-centos6-build CentosOS 6 image for GPDB 6 compilation 0
And now I want to know the tags of the image named ansible/centos7-ansible
.
We will make 2 examples with mjson and no mjson.
Without mjson.
root@linux:~# curl https://registry.hub.docker.com//v1/repositories/ansible/centos7-ansible/tags [{"layer": "", "name": "latest"}, {"layer": "", "name": "1.7"}, {"layer": "", "name": "1.8"}, {"layer": "", "name": "devel"}, {"layer": "", "name": "master"}, {"layer": "", "name": "stable"}]
And with mjson.
root@linux:~# curl https://registry.hub.docker.com//v1/repositories/ansible/centos7-ansible/tags | python -mjson.tool % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 191 0 191 0 0 185 0 --:--:-- 0:00:01 --:--:-- 185 [ { "layer": "", "name": "latest" }, { "layer": "", "name": "1.7" }, { "layer": "", "name": "1.8" }, { "layer": "", "name": "devel" }, { "layer": "", "name": "master" }, { "layer": "", "name": "stable" } ]
You see the results are different. With mjson, we have a better looking result.
Conclusion
This is just a simple trick, it does not require you to have a deep understanding of docker. But it is a very useful thing because you don’t always have a browser to use. You work with the command line server and you must use the command. Right?
«« How to search for a container imageIntroducing the Rocket Chat system »»