1、docker node inspect 简介
docker node inspect
是用于显示 Docker 集群中节点的详细信息。它可以用于获取有关节点的配置、状态和元数据等信息,以及与其他 Docker 命令一起使用来监视和管理 Docker 集群。返回节点的信息。默认情况下,此命令将所有结果渲染为JSON数组。可以指定另一种格式来为每个结果执行给定的模板。Go的text/template包描述了该格式的所有细节。
参考文档:https://docs.docker.com/engine/reference/commandline/node_inspect/
注意:这是一个集群管理命令,必须在集群管理器节点上执行。
2、docker node inspect 语法
docker node inspect [OPTIONS] self|NODE [NODE...]
3、docker node inspect 命令
1)检查查看节点
docker node inspect swarm-manager
输出:
[ { "ID": "e216jshn25ckzbvmwlnh5jr3g", "Version": { "Index": 10 }, "CreatedAt": "2017-05-16T22:52:44.9910662Z", "UpdatedAt": "2017-05-16T22:52:45.230878043Z", "Spec": { "Role": "manager", "Availability": "active" }, "Description": { "Hostname": "swarm-manager", "Platform": { "Architecture": "x86_64", "OS": "linux" }, "Resources": { "NanoCPUs": 1000000000, "MemoryBytes": 1039843328 }, "Engine": { "EngineVersion": "17.06.0-ce", "Plugins": [ { "Type": "Volume", "Name": "local" }, { "Type": "Network", "Name": "overlay" }, { "Type": "Network", "Name": "null" }, { "Type": "Network", "Name": "host" }, { "Type": "Network", "Name": "bridge" }, { "Type": "Network", "Name": "overlay" } ] }, "TLSInfo": { "TrustRoot": "-----BEGIN CERTIFICATE-----\nMIIBazCCARCgAwIBAgIUOzgqU4tA2q5Yv1HnkzhSIwGyIBswCgYIKoZIzj0EAwIw\nEzERMA8GA1UEAxMIc3dhcm0tY2EwHhcNMTcwNTAyMDAyNDAwWhcNMzcwNDI3MDAy\nNDAwWjATMREwDwYDVQQDEwhzd2FybS1jYTBZMBMGByqGSM49AgEGCCqGSM49AwEH\nA0IABMbiAmET+HZyve35ujrnL2kOLBEQhFDZ5MhxAuYs96n796sFlfxTxC1lM/2g\nAh8DI34pm3JmHgZxeBPKUURJHKWjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB\nAf8EBTADAQH/MB0GA1UdDgQWBBS3sjTJOcXdkls6WSY2rTx1KIJueTAKBggqhkjO\nPQQDAgNJADBGAiEAoeVWkaXgSUAucQmZ3Yhmx22N/cq1EPBgYHOBZmHt0NkCIQC3\nzONcJ/+WA21OXtb+vcijpUOXtNjyHfcox0N8wsLDqQ==\n-----END CERTIFICATE-----\n", "CertIssuerSubject": "MBMxETAPBgNVBAMTCHN3YXJtLWNh", "CertIssuerPublicKey": "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAExuICYRP4dnK97fm6OucvaQ4sERCEUNnkyHEC5iz3qfv3qwWV/FPELWUz/aACHwMjfimbcmYeBnF4E8pRREkcpQ==" } }, "Status": { "State": "ready", "Addr": "168.0.32.137" }, "ManagerStatus": { "Leader": true, "Reachability": "reachable", "Addr": "168.0.32.137:2377" } } ]
2)格式化输出(--format)
docker node inspect --format '{{ .ManagerStatus.Leader }}' self false
使用--format=pretty
或--pretty
简写方式美化打印输出:
docker node inspect --format=pretty self ID: e216jshn25ckzbvmwlnh5jr3g Hostname: swarm-manager Joined at: 2017-05-16 22:52:44.9910662 +0000 utc Status: State: Ready Availability: Active Address: 172.17.0.2 Manager Status: Address: 172.17.0.2:2377 Raft Status: Reachable Leader: Yes Platform: Operating System: linux Architecture: x86_64 Resources: CPUs: 4 Memory: 7.704 GiB Plugins: Network: overlay, bridge, null, host, overlay Volume: local Engine Version: 17.06.0-ce TLS Info: TrustRoot: -----BEGIN CERTIFICATE----- MIIBazCCARCgAwIBAgIUOzgqU4tA2q5Yv1HnkzhSIwGyIBswCgYIKoZIzj0EAwIw EzERMA8GA1UEAxMIc3dhcm0tY2EwHhcNMTcwNTAyMDAyNDAwWhcNMzcwNDI3MDAy NDAwWjATMREwDwYDVQQDEwhzd2FybS1jYTBZMBMGByqGSM49AgEGCCqGSM49AwEH A0IABMbiAmET+HZyve35ujrnL2kOLBEQhFDZ5MhxAuYs96n796sFlfxTxC1lM/2g Ah8DI34pm3JmHgZxeBPKUURJHKWjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB Af8EBTADAQH/MB0GA1UdDgQWBBS3sjTJOcXdkls6WSY2rTx1KIJueTAKBggqhkjO PQQDAgNJADBGAiEAoeVWkaXgSUAucQmZ3Yhmx22N/cq1EPBgYHOBZmHt0NkCIQC3 zONcJ/+WA21OXtb+vcijpUOXtNjyHfcox0N8wsLDqQ== -----END CERTIFICATE----- Issuer Public Key: MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAExuICYRP4dnK97fm6OucvaQ4sERCEUNnkyHEC5iz3qfv3qwWV/FPELWUz/aACHwMjfimbcmYeBnF4E8pRREkcpQ== Issuer Subject: MBMxETAPBgNVBAMTCHN3YXJtLWNh
4、命令选项
命令 | 描述 |
--format , -f | 使用自定义模板格式化输出: ‘json’:以 JSON 格式打印 ‘TEMPLATE’:使用给定的 Go 模板打印输出。 请参阅 https://docs.docker.com/go/formatting/ 了解有关使用模板格式化输出的更多信息。 |
--pretty | 以人性化的格式打印信息 |
5、子命令
命令 | 描述 |
docker node demote | 将一个或多个节点从 Swarm 中的管理节点降级 |
docker node inspect | 显示一个或多个节点的详细信息 |
docker node ls | 列出Swarm中的节点 |
docker node promote | 将一个或多个节点提升为 Swarm 中的管理节点 |
docker node ps | 列出运行在一个或多个节点上的任务,默认为当前节点 |
docker node rm | 从 Swarm 中移除一个或多个节点 |
docker node update | 更新一个节点 |