Description and Introduction Docker inspect is a native command of the Docker client, which is used to view the underlying basic information of Docker objects. Including container ID, creation time, running status, startup parameters, directory mounting, network configuration, etc. In addition, this command can also be used to view the information of the docker image. The official description is as follows:
grammar The syntax is as follows: docker inspect [OPTIONS] NAME|ID [NAME|ID...] OPTIONS The following table is taken from the official website
As shown in the table above, --type is used to specify the docker object type, such as container, image. This can be used when the container and the image have the same name, and is used less frequently. For example, if a container on your machine is named redis and an image is redis:latest, you can use the following command to view the image information. If the type parameter is not used, container information is returned: # View redis:latest image information docker inspect --type=image redis # View the redis container information docker inspect redis --size is used to view the file size of the container. With this parameter, the output will include SizeRootFs and SizeRw (I am not sure what these two values mean yet, and I hope someone in the know can let me know). The above two parameters are rarely used. --format is the most practical and is used more frequently. From the table description, we can see that the parameter value passed in should be a template in the go language. It is very powerful and can perform many operations of Go functions. Since I haven't gotten started with the Go language yet, I won't talk too much about its acrobatics here to avoid making mistakes. Let me talk about the commonly used ones below. practice In practice, we often only need to view part of the information, such as directory mounting information and network information. When we directly enter docker inspect container, all the information of the container will be output, which seems bloated and it is not convenient for us to turn pages in the command line. At this point, the practicality of --format is reflected. Common operations in practice are as follows View directory mount information Enter the following command to output the container's Mounts information, and you can see the specific mount locations of each directory in the container on the host machine. docker inspect --format="{{json .Mounts}}" container The json in the parameter is the method name of the Go language, followed by the value of Mounts converted to json. It is also possible to remove json. #Use python's json module to beautify docker inspect --format="{{json .Mounts}}" container | python -m json.tool #Use jq to beautify docker inspect --format="{{json .Mounts}}" container | jq View container network information To view network information, you can use the following command: #View complete network information docker inspect --format="{{json .NetworkSettings}}" container | jq #View network port mapping docker inspect --format="{{json .NetworkSettings.Ports}}" container | jq # View the network IP, gateway and other information of the container docker inspect --format="{{json .NetworkSettings.Networks}}" container | jq Extended Learning If you are interested, you can also make full use of this --format parameter, because it is the template syntax of Go, which can almost write Go code. For example, in the above command, json is the method name of go. Therefore, you can combine other Go methods (such as range, split) to perform acrobatics, but this article will not teach you how to do it. References The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: WeChat applet implements a simple calculator
>>: 15 important variables you must know about MySQL performance tuning (summary)
Preface: Based on a recent medical mobile project...
1. What is ElasticSearch? Elasticsearch is also d...
1. Introduction When writing animation effects fo...
Table of contents output output.path output.publi...
Today, we use uniapp to integrate Echarts to disp...
1. Get the image #Specify the version that includ...
<frameset></frameset> is familiar to e...
1. Check the software installation path: There is...
Preface Forgotten passwords are a problem we ofte...
background Before we know it, a busy year is comi...
By default, Docker runs over a non-networked UNIX...
Table of contents 1. Project Integration 1. CDN i...
This article uses examples to illustrate the func...
Busybox: A Swiss Army knife filled with small com...
Table of contents Preface Rendering setTable comp...