本文共 7771 字,大约阅读时间需要 25 分钟。
run
$ sudo docker run ubuntu:14.04 /bin/echo 'Hello world'Hello world
sudo docker start silly_bohrsilly_bohr$ sudo docker stop silly_bohrsilly_bohr$ sudo docker restart silly_bohrsilly_bohr
sudo docker ps
$ sudo docker ps -lCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES84391d1de0fc ubuntu:14.04 /bin/echo Hello worl 31 minutes ago Exit 0 romantic_ritchie
$ sudo docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES13b2a4a31455 ubuntu:14.04 /bin/bash 3 hours ago Up 3 hours silly_bohr$ sudo docker top silly_bohrUID PID PPID C STIME TTY TIME CMDroot 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 imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu 14.10 58faa899733f 2 weeks ago 196 MBubuntu utopic 58faa899733f 2 weeks ago 196 MBubuntu precise ea7d6801c538 3 weeks ago 127.5 MBubuntu 12.04 ea7d6801c538 3 weeks ago 127.5 MBubuntu 12.10 c5881f11ded9 4 weeks ago 172.2 MBubuntu quantal c5881f11ded9 4 weeks ago 172.2 MBubuntu 13.04 463ff6be4238 4 weeks ago 169.4 MBubuntu raring 463ff6be4238 4 weeks ago 169.4 MBubuntu 13.10 195eb90b5349 4 weeks ago 184.7 MBubuntu saucy 195eb90b5349 4 weeks ago 184.7 MBubuntu 14.04 e54ca5efa2e9 4 weeks ago 276.5 MBubuntu latest e54ca5efa2e9 4 weeks ago 276.5 MBubuntu trusty e54ca5efa2e9 4 weeks ago 276.5 MBubuntu 10.04 3db9c44f4520 12 weeks ago 183 MBubuntu lucid 3db9c44f4520 12 weeks ago 183 MB
$ sudo docker pull centosPulling repository centosb7de3133ff98: Pulling dependent layers5cc9e91966f7: Pulling fs layer511136ea3c5a: Download completeef52fb1fe610: Download complete
显示容器运行日志,用于排查异常情况
例如下面是nginx容易启动出错日志
[root@netkiller]# docker logs my-nginx-container nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80nginx: [emerg] invalid server name or wildcard "www.*.com" on 0.0.0.0:80
镜像历史纪录
# docker history centos:tomcatIMAGE CREATED CREATED BY SIZE COMMENT2faf9a2d2bdc 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 Netkiller9 days ago /bin/sh -c #(nop) LABEL name=CentOS Base ... 0 B 9 days ago /bin/sh -c #(nop) ADD file:d22a9c627d1d1f3... 193 MB
原文出处:Netkiller 系列 手札
本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。