获取Docker中容器的信息
查看系统中的容器# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
431dc327cd14 ubuntu:latest "/bin/bash -c 'while 2 hours ago Exited (-1) About an hour ago daemon_ubuntu
1ce9f640478d ubuntu:latest "/bin/bash" 2 hours ago Exited (0) 2 hours ago ovcer_the_container
8c342c0c275c ubuntu:latest "/bin/bash" 3 hours ago Exited (0) 3 hours ago sharp_bohr
查看daemon_ubuntu容器的详细信息
# docker inspect daemon_ubuntu
[{
"AppArmorProfile": "",
"Args": [
"-c",
"while true; do echo hello world; sleep 1;done"
],
"Config": {
"AttachStderr": false,
"AttachStdin": false,
"AttachStdout": false,
"Cmd": [
"/bin/bash",
"-c",
"while true; do echo hello world; sleep 1;done"
],
"CpuShares": 0,
"Cpuset": "",
"Domainname": "",
"Entrypoint": null,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"ExposedPorts": null,
"Hostname": "431dc327cd14",
"Image": "ubuntu",
"Memory": 0,
"MemorySwap": 0,
"NetworkDisabled": false,
"OnBuild": null,
"OpenStdin": false,
"PortSpecs": null,
"StdinOnce": false,
"Tty": false,
"User": "",
"Volumes": null,
"WorkingDir": ""
},
"Created": "2014-12-28T10:50:52.21214491Z",
"Driver": "devicemapper",
"ExecDriver": "native-0.2",
"HostConfig": {
"Binds": null,
"CapAdd": null,
"CapDrop": null,
"ContainerIDFile": "",
"Devices": [],
"Dns": null,
"DnsSearch": null,
"ExtraHosts": null,
"Links": null,
"LxcConf": [],
"NetworkMode": "bridge",
"PortBindings": {},
"Privileged": false,
"PublishAllPorts": false,
"RestartPolicy": {
"MaximumRetryCount": 0,
"Name": ""
},
"SecurityOpt": null,
"VolumesFrom": null
},
"HostnamePath": "/var/lib/docker/containers/431dc327cd14c9df4183589fb94eeab64fe1e1a5db10c48339d08a2a9b1675bb/hostname",
"HostsPath": "/var/lib/docker/containers/431dc327cd14c9df4183589fb94eeab64fe1e1a5db10c48339d08a2a9b1675bb/hosts",
"Id": "431dc327cd14c9df4183589fb94eeab64fe1e1a5db10c48339d08a2a9b1675bb",
"Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2",
"MountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c188,c747",
"Name": "/daemon_ubuntu",
"NetworkSettings": {
"Bridge": "",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"MacAddress": "",
"PortMapping": null,
"Ports": null
},
"Path": "/bin/bash",
"ProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c188,c747",
"ResolvConfPath": "/var/lib/docker/containers/431dc327cd14c9df4183589fb94eeab64fe1e1a5db10c48339d08a2a9b1675bb/resolv.conf",
"State": {
"ExitCode": -1,
"FinishedAt": "2014-12-28T11:14:01.24980761Z",
"Paused": false,
"Pid": 0,
"Restarting": false,
"Running": false,
"StartedAt": "2014-12-28T10:50:52.879797683Z"
},
"Volumes": {},
"VolumesRW": {}
}
获取容器的运行状态
# docker inspect --format='{{ .State.Running }}' daemon_ubuntu
false
获取容器的IP地址
# docker inspect --format '{{ .NetworkSettings.IPAddress }}' daemon_ubuntu
页:
[1]