Linux入门教程:Docker命令行参考(38) – docker service inspect显示服务详细信息,dockerservice这个命令必须在man


Usage:  docker service inspect [OPTIONS] SERVICE [SERVICE...]   Display detailed information on one or more services   Options:   -f, --format string   Format the output using the given go template       --help            Print usage       --pretty          Print the information in a human friendly format.

查看指定服务的信息。这个命令必须在manager节点上执行。

默认情下,以JSON数组输出结果。如果指定了格式,就按给定的格式模板格式化每个结果。

示例

通过名称或ID查看服务

例如,有如下服务:

$ docker service ls ID            NAME      REPLICAS  IMAGE         COMMAND dmu1ept4cxcf  redis     3/3       redis:3.0.6

docker service inspect redis和docker service inspect dmu1ept4cxcf都是输出同样的结果:

$ docker service inspect redis [     {         "ID": "dmu1ept4cxcfe8k8lhtux3ro3",         "Version": {             "Index": 12         },         "CreatedAt": "2016-06-17T18:44:02.558012087Z",         "UpdatedAt": "2016-06-17T18:44:02.558012087Z",         "Spec": {             "Name": "redis",             "TaskTemplate": {                 "ContainerSpec": {                     "Image": "redis:3.0.6"                 },                 "Resources": {                     "Limits": {},                     "Reservations": {}                 },                 "RestartPolicy": {                     "Condition": "any",                     "MaxAttempts": 0                 },                 "Placement": {}             },             "Mode": {                 "Replicated": {                     "Replicas": 1                 }             },             "UpdateConfig": {},             "EndpointSpec": {                 "Mode": "vip"             }         },         "Endpoint": {             "Spec": {}         }     } ] $ docker service inspect dmu1ept4cxcf [     {         "ID": "dmu1ept4cxcfe8k8lhtux3ro3",         "Version": {             "Index": 12         },         ...     } ]

使用pretty-print查看服务

可以使用–pretty选项以人类可读的格式打印输出,而不是默认的JSON格式输出。

$ docker service inspect --pretty frontend ID:   c8wgl7q4ndfd52ni6qftkvnnp Name:   frontend Labels:  - org.example.projectname=demo-app Mode:   REPLICATED  Replicas:    5 Placement: UpdateConfig:  Parallelism: 0 ContainerSpec:  Image:   nginx:alpine Resources: Ports:  Name =  Protocol = tcp  TargetPort = 443  PublishedPort = 4443

查找服务的任务数

–format选项可以用来获取关于服务的指定信息。例如,下面的命令输出redis服务的副本数。

$ docker service inspect --format='{{.Spec.Mode.Replicated.Replicas}}' redis 10

相关内容