Docker 常用命令 – docker info

概要

1、版本信息

Ubuntu 18.04.5
Docker 19.03.6

命令解释

1、命令描述

docker info 用于显示 docker 的系统级信息,比如内核,镜像数,容器数等。

基于在使用的存储驱动程序,可以显示额外的信息。例如池名称,数据文件,元数据文件,数据空间使用情况,总共数据空间情况,元数据空间使用,总共的元数据空间情况等。

数据文件是镜像存储的地方,元数据文件是存储镜像相关的元数据的地方。

当第一次运行 Docker 时会从 /var/lib/docker 挂载点的物理卷的可用空间中分配一定数量的数据空间和元数据空间。

2、用法a

docker info [OPTIONS]

docker version 是固定命令关键字,[OPTIONS] 表示是该命令有可选参数。默认情况下,docker version 会返回类 yaml 文件格式的所有版本信息。

如果传递了格式化参数(--format)和参数值,那么该命令会按照传递的 --format 参数的值进行渲染,可见示例部分。

3、可选参数 [OPTIONS]

速记参数名
完整参数名
参数值类型
默认值
参数描述
-f
<div--<format
string
用给定的 Go 模板来格式化输出

用法示例

1、docker info

➜  ~ docker info                           
Client:
 Debug Mode: false
Server:
 Containers: 9
  Running: 0
  Paused: 0
  Stopped: 9
 Images: 7
 Server Version: 19.03.6
 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: 
 runc version: 
 init version: 
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.4.0-42-generic
 Operating System: Ubuntu 18.04.5 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.61GiB
 Name: ubuntu
 ID: 24JO:56SN:3QEK:RAJR:VNTO:6M6K:THLE:7IAL:2I3H:HUN2:TXZD:R3O6
 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
 Registry Mirrors:
  http://hub-mirror.c.163.com/
 Live Restore Enabled: false
WARNING: No swap limit support

2、docker info --format='{{.KernelVersion}}'

➜  ~ docker info -f '{{.KernelVersion}}'      
5.4.0-42-generic

根据给定的 Go 模板,只输出 docker 的内核版本号。

3、docker info --format '{{json .}}'

➜  ~ docker info --format '{{json .}}'
{"ID":"24JO:56SN:3QEK:RAJR:VNTO:6M6K:THLE:7IAL:2I3H:HUN2:TXZD:R3O6","Containers":9,"ContainersRunning":0,"ContainersPaused":0,"ContainersStopped":9,"Images":7,"Driver":"overlay2","DriverStatus":[["Backing Filesystem","extfs"],["Supports d_type","true"],["Native Overlay Diff","true"]],"SystemStatus":null,"Plugins":{"Volume":["local"],"Network":["bridge","host","ipvlan","macvlan","null","overlay"],"Authorization":null,"Log":["awslogs","fluentd","gcplogs","gelf","journald","json-file","local","logentries","splunk","syslog"]},"MemoryLimit":true,"SwapLimit":false,"KernelMemory":true,"KernelMemoryTCP":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"PidsLimit":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":21,"OomKillDisable":true,"NGoroutines":34,"SystemTime":"2020-09-10T21:47:09.934794426-07:00","LoggingDriver":"json-file","CgroupDriver":"cgroupfs","NEventsListener":0,"KernelVersion":"5.4.0-42-generic","OperatingSystem":"Ubuntu 18.04.5 LTS","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"AllowNondistributableArtifactsCIDRs":[],"AllowNondistributableArtifactsHostnames":[],"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":["http://hub-mirror.c.163.com/"],"Secure":true,"Official":true}},"Mirrors":["http://hub-mirror.c.163.com/"]},"NCPU":4,"MemTotal":16763027456,"GenericResources":null,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"ubuntu","Labels":[],"ExperimentalBuild":false,"ServerVersion":"19.03.6","ClusterStore":"","ClusterAdvertise":"","Runtimes":{"runc":{"path":"runc"}},"DefaultRuntime":"runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null},"LiveRestoreEnabled":false,"Isolation":"","InitBinary":"docker-init","ContainerdCommit":{"ID":"","Expected":""},"RuncCommit":{"ID":"","Expected":""},"InitCommit":{"ID":"","Expected":""},"SecurityOptions":["name=apparmor","name=seccomp,profile=default"],"Warnings":["WARNING: No swap limit support"],"ClientInfo":{"Debug":false,"Plugins":[],"Warnings":null}}

4、全局可选参数 -D

全局可选参数 -D 可以使所有的 docker 命令输出调试信息。如下示例

➜  docker docker -D info
Client:
 Debug Mode: true
Server:
 Containers: 9
  Running: 0
  Paused: 0
  Stopped: 9
 Images: 8
 Server Version: 19.03.6
 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: 
 runc version: 
 init version: 
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.4.0-42-generic
 Operating System: Ubuntu 18.04.5 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.61GiB
 Name: ubuntu
 ID: 24JO:56SN:3QEK:RAJR:VNTO:6M6K:THLE:7IAL:2I3H:HUN2:TXZD:R3O6
 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
 Registry Mirrors:
  http://hub-mirror.c.163.com/
 Live Restore Enabled: false
WARNING: No swap limit support

注:docker info 中显示的镜像数是唯一镜像的数量,即同一个名称的镜像的多个版本只会统计一次。

如下示例,centos 镜像有两个 tags 分别是 6、7,但 docker info 中只统计了一次,所以 docker info 中的总镜像数是 8.

➜  ~ docker images                
REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
kibana_v0.1                      latest              016a70f54769        2 weeks ago         803MB
ubuntu                           latest              4e2eef94cd6b        3 weeks ago         73.9MB
centos                           7                   7e6257c9f8d8        4 weeks ago         203MB
mysql/mysql-server               5.7                 9c31a29b3f30        2 months ago        322MB
mcr.microsoft.com/mssql/server   2017-latest         81c7e82f3678        2 months ago        1.49GB
kibana                           6.7.0               a19f604cd838        18 months ago       675MB
elasticsearch                    6.7.0               02982be5777d        18 months ago       810MB
centos                           6                   d0957ffdf8a2        18 months ago       194MB
➜  ~ docker info -f '{{.Images}}'
8

附录

1、参考

docker info 官方文档:

https://docs.docker.com/engine/reference/commandline/info

Go 模板官方文档:

http://golang.org/pkg/text/template/

2、docker info --help

➜  ~ docker info --help                        
Usage:  docker info [OPTIONS]
Display system-wide information
Options:
  -f, --format string   Format the output using the given Go template

You may also like...

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注