除了通过docker ps 命令获取容器信息,还可以使用docker inspect 来获得更多的容器信息。
[root@VM-0-16-centos ~]# docker inspect daemon_wdf
[
{
"Id": "0c3064d39a44ca61b0570a6d33d30672a3dffd1eabac7f637801f8c2288de940",
"Created": "2020-09-27T08:28:52.010288391Z",
"Path": "/bin/sh",
"Args": [
"-c",
"while true;do echo hello world;sleep 1;done"
],
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 0,
"ExitCode": 137,
"Error": "",
"StartedAt": "2020-09-27T10:00:36.764996156Z",
"FinishedAt": "2020-09-27T10:00:49.337337899Z"
},
"Image": "sha256:bb0eaf4eee00c28cb8ffd54e571dd225f1dd2ed8d8751b2835c31e84188bf2de",
"ResolvConfPath": "/var/lib/docker/containers/0c3064d39a44ca61b0570a6d33d30672a3dffd1eabac7f637801f8c2288de940/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/0c3064d39a44ca61b0570a6d33d30672a3dffd1eabac7f637801f8c2288de940/hostname",
"HostsPath": "/var/lib/docker/containers/0c3064d39a44ca61b0570a6d33d30672a3dffd1eabac7f637801f8c2288de940/hosts",
"LogPath": "/var/lib/docker/containers/0c3064d39a44ca61b0570a6d33d30672a3dffd1eabac7f637801f8c2288de940/0c3064d39a44ca61b0570a6d33d30672a3dffd1eabac7f637801f8c2288de940-json.log",
"Name": "/daemon_wdf",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
.....太长了就不复制了
可以看出docker inspect命令会对容器进行详细的检查,然后返回其配置信息,包括名称,命令,网络配置以及很多有用的数据。
也可以使用-f 或者 --format 选定期望查询的结果。
[root@VM-0-16-centos ~]# docker inspect -f '{{.State}}' daemon_wdf
{exited false false false false false 0 137 2020-09-27T10:00:36.764996156Z 2020-09-27T10:00:49.337337899Z <nil>}
[root@VM-0-16-centos ~]# docker inspect -f '{{.State.Status}}' daemon_wdf
exited
[root@VM-0-16-centos ~]# docker inspect -f '{{.Args}}' daemon_wdf
[-c while true;do echo hello world;sleep 1;done]
[root@VM-0-16-centos ~]#
如果是 --format 要写成
docker inspect --format='{{.State.Status}}' daemon_wdf
查询多个字段的值则在后面引号内写入多个值。
docker inspect --format='{{.State.Status}} {{.NetworkSettings.Networks.bridge}}' daemon_wdf
同时还支持同事查询多个容器的值。
[root@VM-0-16-centos ~]# docker inspect --format='{{.Name}} {{.State.Status}}}' daemon_wdf daemon_dave
/daemon_wdf exited}
/daemon_dave exited}
[root@VM-0-16-centos ~]#
除了查看容器信息还可通过docker的目录来了解Docker原理。
/var/lib/docker/ 该目录存放Docker镜像,容器,及容器的配置。
[root@VM-0-16-centos ~]# cd /var/lib/docker/
[root@VM-0-16-centos docker]# ls
builder buildkit containers image network overlay2 plugins runtimes swarm tmp trust volumes
所有的容器都存在/var/lib/docker/containers 这个目录下
[root@VM-0-16-centos containers]# ls
0c3064d39a44ca61b0570a6d33d30672a3dffd1eabac7f637801f8c2288de940 116db8f4f78001a688646d244b375c3fc2eb22a1cd2950805acf212a17c0dd3e
[root@VM-0-16-centos containers]#