作者: 耗子007
所有命令均基于docker1.11版本
上面的分析基本包含了容器相关的大部分命令,剩余一些系统信息、容器底层信息、容器插件或者其他组件相关的命令。 但是本章只关注系统信息和容器底层信息相关的命令,其他命令就不做介绍,后续有时间可能会补充。
获取Docker系统相关信息 1 2 3 4 5 Usage: docker info [OPTIONS] Display system-wide information --help Print usage
例如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 $ docker -D info Containers: 14 Running: 3 Paused: 1 Stopped: 10 Images: 52 Server Version: 1.9.0 Storage Driver: aufs Root Dir: /var/lib/docker/aufs Backing Filesystem: extfs Dirs: 545 Dirperm1 Supported: true Execution Driver: native-0.2 Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge null host Kernel Version: 3.19.0-22-generic OSType: linux Architecture: x86_64 Operating System: Ubuntu 15.04 CPUs: 24 Total Memory: 62.86 GiB Name: docker ID: I54V:OLXT:HVMM:TPKO:JPHQ:CQCD:JNLC:O3BZ:4ZVJ:43XJ:PFHZ:6N2S Docker Root Dir: /var/lib/docker Debug mode (client): true Debug mode (server): true File Descriptors: 59 Goroutines: 159 System Time: 2015-09-23T14:04:20.699842089+08:00 EventsListeners: 0 Init SHA1: Init Path: /usr/bin/docker Docker Root Dir: /var/lib/docker Http Proxy: http://test :test @localhost:8080 Https Proxy: https://test :test @localhost:8080 WARNING: No swap limit support Username: svendowideit Registry: [https://index.docker.io/v1/] Labels: storage=ssd
这些信息里面,一般比较关注的是Storage和Logging驱动、插件、Registry地址等。 注:全局-D可以是docker命令输出调试信息,在发送问题报告的时候,最好带上-D。
容器或镜像的底层信息 有时可能需要知道容器或者镜像的一些底层信息,可以使用inspect命令获取。
1 2 3 4 5 6 7 8 9 Usage: docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...] Return low-level information on a container or image -f, --format="" Format the output using the given go template --help Print usage --type =container|image Return JSON for_specified_type, permissible values are "image" or "container" -s, --size Display total file sizes if the type is container
format命令默认会把结果以JSON格式输出。 注意:
默认情况下,当容器名和镜像名相同时,format会输容器的结果
当时如果指定了–format,format会返回两个的格式化结果
关于–format选项可以参考Go语言的模板,这里只介绍简单的用法,例如获取容器的ID:
1 docker inspect -f='{ {.Id} }' haozi
获取Docker版本信息 1 2 3 4 5 6 Usage: docker version [OPTIONS] Show the Docker version information. -f, --format="" Format the output using the given go template --help Print usage
version命令可以获取Docker版本相关信息,可以用–format来格式化输出,如方法前面。 例如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 $ docker version Client: Version: 1.11.2 UnicornVersion: 1.11.2.11.ict API version: 1.23 Go version: go1.7.4 Git commit: 008dfcd Built: Tue Feb 7 10:58:04 2017 OS/Arch: linux/amd64 Server: Version: 1.11.2 UnicornVersion: 1.11.2.11.ict API version: 1.23 Go version: go1.7.4 Git commit: 008dfcd Built: Tue Feb 7 10:58:04 2017 OS/Arch: linux/amd64
这里比较重要的信息是Docker、API、Go等的版本,例如,Client和Server的版本号不一致可能有各种问题。