166.7. docker 命令
sudo docker start silly_bohr silly_bohr $ sudo docker stop silly_bohr silly_bohr $ sudo docker restart silly_bohr silly_bohr
sudo docker ps
$ sudo docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 84391d1de0fc ubuntu:14.04 /bin/echo Hello worl 31 minutes ago Exit 0 romantic_ritchie
$ sudo docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 13b2a4a31455 ubuntu:14.04 /bin/bash 3 hours ago Up 3 hours silly_bohr $ sudo docker top silly_bohr UID PID PPID C STIME TTY TIME CMD root 23225 22908 0 12:17 pts/14 00:00:00 /bin/bash
$ sudo docker inspect silly_bohr
[{
"ID": "13b2a4a3145528d087c9d1580fa78aaa52e8a9bb973c9da923bceb9f9b9e7e5a",
"Created": "2014-07-17T04:17:45.262480632Z",
"Path": "/bin/bash",
"Args": [],
"Config": {
"Hostname": "13b2a4a31455",
"Domainname": "",
"User": "",
"Memory": 0,
"MemorySwap": 0,
"CpuShares": 0,
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"PortSpecs": null,
"ExposedPorts": null,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"HOME=/",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"Dns": [
"8.8.8.8",
"8.8.4.4"
],
"Image": "ubuntu",
"Volumes": null,
"VolumesFrom": "",
"WorkingDir": "",
"Entrypoint": null,
"NetworkDisabled": false,
"OnBuild": null
},
"State": {
"Running": true,
"Pid": 23225,
"ExitCode": 0,
"StartedAt": "2014-07-17T04:17:45.672269614Z",
"FinishedAt": "0001-01-01T00:00:00Z",
"Ghost": false
},
"Image": "e54ca5efa2e962582a223ca9810f7f1b62ea9b5c3975d14a5da79d3bf6020f37",
"NetworkSettings": {
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"Gateway": "172.17.42.1",
"Bridge": "docker0",
"PortMapping": null,
"Ports": {}
},
"ResolvConfPath": "/var/lib/docker/containers/13b2a4a3145528d087c9d1580fa78aaa52e8a9bb973c9da923bceb9f9b9e7e5a/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/13b2a4a3145528d087c9d1580fa78aaa52e8a9bb973c9da923bceb9f9b9e7e5a/hostname",
"HostsPath": "/var/lib/docker/containers/13b2a4a3145528d087c9d1580fa78aaa52e8a9bb973c9da923bceb9f9b9e7e5a/hosts",
"Name": "/silly_bohr",
"Driver": "aufs",
"ExecDriver": "native-0.1",
"Volumes": {},
"VolumesRW": {},
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LxcConf": [],
"Privileged": false,
"PortBindings": {},
"Links": null,
"PublishAllPorts": false
}
}]
$ sudo docker inspect -f '{{ .NetworkSettings.IPAddress }}' silly_bohr
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 14.10 58faa899733f 2 weeks ago 196 MB ubuntu utopic 58faa899733f 2 weeks ago 196 MB ubuntu precise ea7d6801c538 3 weeks ago 127.5 MB ubuntu 12.04 ea7d6801c538 3 weeks ago 127.5 MB ubuntu 12.10 c5881f11ded9 4 weeks ago 172.2 MB ubuntu quantal c5881f11ded9 4 weeks ago 172.2 MB ubuntu 13.04 463ff6be4238 4 weeks ago 169.4 MB ubuntu raring 463ff6be4238 4 weeks ago 169.4 MB ubuntu 13.10 195eb90b5349 4 weeks ago 184.7 MB ubuntu saucy 195eb90b5349 4 weeks ago 184.7 MB ubuntu 14.04 e54ca5efa2e9 4 weeks ago 276.5 MB ubuntu latest e54ca5efa2e9 4 weeks ago 276.5 MB ubuntu trusty e54ca5efa2e9 4 weeks ago 276.5 MB ubuntu 10.04 3db9c44f4520 12 weeks ago 183 MB ubuntu lucid 3db9c44f4520 12 weeks ago 183 MB
显示容器运行日志,用于排查异常情况
例如下面是nginx容易启动出错日志
[root@netkiller]# docker logs my-nginx-container nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80 nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80 nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80 nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80 nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80 nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80
镜像历史纪录
# docker history centos:tomcat IMAGE CREATED CREATED BY SIZE COMMENT 2faf9a2d2bdc 22 hours ago /bin/sh -c #(nop) CMD ["catalina.sh" "run"] 0 B 8e12c1e8fd89 22 hours ago /bin/sh -c #(nop) EXPOSE 8080/tcp 0 B 35158d8231c5 22 hours ago /bin/sh -c #(nop) VOLUME [/srv/tomcat/temp] 0 B 4302c5c13241 22 hours ago /bin/sh -c #(nop) VOLUME [/srv/tomcat/work] 0 B 53537696aa19 22 hours ago /bin/sh -c #(nop) ADD file:ac42f23f37092b9... 298 B be04ba27a9ae 23 hours ago /bin/sh -c set -x && wget -O tomcat.tar.... 8.75 MB 847be662a35f 5 days ago /bin/sh -c #(nop) ENV TOMCAT_ASC_URL=http... 0 B ac6550346558 5 days ago /bin/sh -c #(nop) ENV TOMCAT_TGZ_URL=http... 0 B 50c12be7ca48 5 days ago /bin/sh -c #(nop) ENV TOMCAT_VERSION=8.5.15 0 B 89c44758e4ae 5 days ago /bin/sh -c #(nop) ENV TOMCAT_MAJOR=8 0 B 560ad98c1b23 5 days ago /bin/sh -c yum install -y java-1.8.0-openj... 236 MB befeedbb7dc7 5 days ago /bin/sh -c #(nop) WORKDIR /srv/tomcat 0 B c85cf394faf8 5 days ago /bin/sh -c mkdir -p "$CATALINA_HOME" 0 B debf78012b2c 5 days ago /bin/sh -c #(nop) ENV PATH=/srv/tomcat/bi... 0 B ccc27f4f3bcf 5 days ago /bin/sh -c #(nop) ENV CATALINA_HOME=/srv/... 0 B 8f351964d568 6 days ago /bin/sh -c #(nop) MAINTAINER Netkiller <n... 0 B 3bee3060bfc8 9 days ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B <missing> 9 days ago /bin/sh -c #(nop) LABEL name=CentOS Base ... 0 B <missing> 9 days ago /bin/sh -c #(nop) ADD file:d22a9c627d1d1f3... 193 MB
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。