Docker命令行帮助(3)


events

  1. Usage :docker events
  2. 从服务器获取实时事件
  3. -since="": 显示以前创建的事件流()

Examples

  1. 在这个例子里你需要运行两个shell

Shell 1:监听事件

  1. sudo docker events

Shell 2:开始和关闭一个容器

  1. $ sudo docker start 4386fb97867d
  2. $ sudo docker stop 4386fb97867d

Shell 1: 再一次。。你会看到下面的事件

  1. [2013-09-03 15:49:26 +0200 CEST] 4386fb97867d: (from 12de384bfb10) start
  2. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  3. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop

查看事件从一个指定的过去的时间段

  1. $ sudo docker events -since 1378216169
  2. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  3. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  4. $ sudo docker events -since '2013-09-03'
  5. [2013-09-03 15:49:26 +0200 CEST] 4386fb97867d: (from 12de384bfb10) start
  6. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  7. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop
  8. $ sudo docker events -since '2013-09-03 15:49:29 +0200 CEST'
  9. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) die
  10. [2013-09-03 15:49:29 +0200 CEST] 4386fb97867d: (from 12de384bfb10) stop

docker events

export

  1. Usage: docker export CONTAINER(容器)
  2. 导出文件系统作为一个tar文档发送到stdout

例子

  1. $ sudo docker export red_panda > latest.tar

docker export

history

  1. Usage: docker history [OPTIONS] IMAGE
  2. 显示镜像的历史操作
  3. -notrunc=false: 不截断输出
  4. -q=false: 只显示数字id

查看docker:last最新创建的镜像

  1. $ docker history docker
  2. ID CREATED CREATED BY
  3. docker:latest 19 hours ago /bin/sh -c #(nop) ADD . in /go/src/github.com/dotcloud/docker
  4. cf5f2467662d 2 weeks ago /bin/sh -c #(nop) ENTRYPOINT ["hack/dind"]
  5. 3538fbe372bf 2 weeks ago /bin/sh -c #(nop) WORKDIR /go/src/github.com/dotcloud/docker
  6. 7450f65072e5 2 weeks ago /bin/sh -c #(nop) VOLUME /var/lib/docker
  7. b79d62b97328 2 weeks ago /bin/sh -c apt-get install -y -q lxc
  8. 36714852a550 2 weeks ago /bin/sh -c apt-get install -y -q iptables
  9. 8c4c706df1d6 2 weeks ago /bin/sh -c /bin/echo -e '[default]\naccess_key=$AWS_ACCESS_KEY\nsecret_key=$AWS_SECRET_KEYn' > /.s3cfg
  10. b89989433c48 2 weeks ago /bin/sh -c pip install python-magic
  11. a23e640d85b5 2 weeks ago /bin/sh -c pip install s3cmd
  12. 41f54fec7e79 2 weeks ago /bin/sh -c apt-get install -y -q python-pip
  13. d9bc04add907 2 weeks ago /bin/sh -c apt-get install -y -q reprepro dpkg-sig
  14. e74f4760fa70 2 weeks ago /bin/sh -c gem install --no-rdoc --no-ri fpm
  15. 1e43224726eb 2 weeks ago /bin/sh -c apt-get install -y -q ruby1.9.3 rubygems libffi-dev
  16. 460953ae9d7f 2 weeks ago /bin/sh -c #(nop) ENV GOPATH=/go:/go/src/github.com/dotcloud/docker/vendor
  17. 8b63eb1d666b 2 weeks ago /bin/sh -c #(nop) ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/goroot/bin
  18. 3087f3bcedf2 2 weeks ago /bin/sh -c #(nop) ENV GOROOT=/goroot
  19. 635840d198e5 2 weeks ago /bin/sh -c cd /goroot/src && ./make.bash
  20. 439f4a0592ba 2 weeks ago /bin/sh -c curl -s https://go.googlecode.com/files/go1.1.2.src.tar.gz | tar -v -C / -xz && mv /go /goroot
  21. 13967ed36e93 2 weeks ago /bin/sh -c #(nop) ENV CGO_ENABLED=0
  22. bf7424458437 2 weeks ago /bin/sh -c apt-get install -y -q build-essential
  23. a89ec997c3bf 2 weeks ago /bin/sh -c apt-get install -y -q mercurial
  24. b9f165c6e749 2 weeks ago /bin/sh -c apt-get install -y -q git
  25. 17a64374afa7 2 weeks ago /bin/sh -c apt-get install -y -q curl
  26. d5e85dc5b1d8 2 weeks ago /bin/sh -c apt-get update
  27. 13e642467c11 2 weeks ago /bin/sh -c echo 'deb http://archive.ubuntu.com/ubuntu precise main universe' > /etc/apt/sources.list
  28. ae6dde92a94e 2 weeks ago /bin/sh -c #(nop) MAINTAINER Solomon Hykes <solomon@dotcloud.com>

带图的都是我本地自己测试的

docker history

images

  1. Usage: docker images [OPTIONS] [NAME]
  2. 列出镜像
  3. -a=false: 显示所有镜像(默认情况下过略掉了用于构建的镜像)
  4. -notrunc=false: 不截断输出
  5. -q=false: 指输出镜像id
  6. -tree=false: 用树形结构输出镜像
  7. -viz=false: graphviz输出镜像图(非官方备注,你需要安装apt-get install graphviz)

列出最近创建的镜像

  1. $ sudo docker images | head
  2. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  3. <none> <none> 77af4d6b9913 19 hours ago 1.089 GB
  4. committest latest b6fa739cedf5 19 hours ago 1.089 GB
  5. <none> <none> 78a85c484f71 19 hours ago 1.089 GB
  6. docker latest 30557a29d5ab 20 hours ago 1.089 GB
  7. <none> <none> 0124422dd9f9 20 hours ago 1.089 GB
  8. <none> <none> 18ad6fad3402 22 hours ago 1.082 GB
  9. <none> <none> f9f1e26352f0 23 hours ago 1.089 GB
  10. tryout latest 2629d1fa0b81 23 hours ago 131.5 MB
  11. <none> <none> 5ed6274db6ce 24 hours ago 1.089 GB

docker images

列出全部的镜像ID

  1. $ sudo docker images -notrunc | head
  2. REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
  3. <none> <none> 77af4d6b9913e693e8d0b4b294fa62ade6054e6b2f1ffb617ac955dd63fb0182 19 hours ago 1.089 GB
  4. committest latest b6fa739cedf5ea12a620a439402b6004d057da800f91c7524b5086a5e4749c9f 19 hours ago 1.089 GB
  5. <none> <none> 78a85c484f71509adeaace20e72e941f6bdd2b25b4c75da8693efd9f61a37921 19 hours ago 1.089 GB
  6. docker latest 30557a29d5abc51e5f1d5b472e79b7e296f595abcf19fe6b9199dbbc809c6ff4 20 hours ago 1.089 GB
  7. <none> <none> 0124422dd9f9cf7ef15c0617cda3931ee68346455441d66ab8bdc5b05e9fdce5 20 hours ago 1.089 GB
  8. <none> <none> 18ad6fad340262ac2a636efd98a6d1f0ea775ae3d45240d3418466495a19a81b 22 hours ago 1.082 GB
  9. <none> <none> f9f1e26352f0a3ba6a0ff68167559f64f3e21ff7ada60366e2d44a04befd1d3a 23 hours ago 1.089 GB
  10. tryout latest 2629d1fa0b81b222fca63371ca16cbf6a0772d07759ff80e8d1369b926940074 23 hours ago 131.5 MB
  11. <none> <none> 5ed6274db6ceb2397844896966ea239290555e74ef307030ebb01ff91b1914df 24 hours ago 1.089 GB

docker images -notrunc

显示图像图片

  1. $ sudo docker images -viz | dot -Tpng -o docker.png

(这里不引用官方的了,我本地测试的)

docker images -viz

显示镜像的曾次结构

  1. $ sudo docker images -tree
  2. ├─8dbd9e392a96 Size: 131.5 MB (virtual 131.5 MB) Tags: ubuntu:12.04,ubuntu:latest,ubuntu:precise
  3. └─27cf78414709 Size: 180.1 MB (virtual 180.1 MB)
  4. └─b750fe79269d Size: 24.65 kB (virtual 180.1 MB) Tags: ubuntu:12.10,ubuntu:quantal
  5. ├─f98de3b610d5 Size: 12.29 kB (virtual 180.1 MB)
  6. └─7da80deb7dbf Size: 16.38 kB (virtual 180.1 MB)
  7. └─65ed2fee0a34 Size: 20.66 kB (virtual 180.2 MB)
  8. └─a2b9ea53dddc Size: 819.7 MB (virtual 999.8 MB)
  9. └─a29b932eaba8 Size: 28.67 kB (virtual 999.9 MB)
  10. └─e270a44f124d Size: 12.29 kB (virtual 999.9 MB) Tags: progrium/buildstep:latest
  11. └─17e74ac162d8 Size: 53.93 kB (virtual 180.2 MB)
  12. └─339a3f56b760 Size: 24.65 kB (virtual 180.2 MB)
  13. └─904fcc40e34d Size: 96.7 MB (virtual 276.9 MB)
  14. └─b1b0235328dd Size: 363.3 MB (virtual 640.2 MB)
  15. └─7cb05d1acb3b Size: 20.48 kB (virtual 640.2 MB)
  16. └─47bf6f34832d Size: 20.48 kB (virtual 640.2 MB)
  17. └─f165104e82ed Size: 12.29 kB (virtual 640.2 MB)
  18. └─d9cf85a47b7e Size: 1.911 MB (virtual 642.2 MB)
  19. └─3ee562df86ca Size: 17.07 kB (virtual 642.2 MB)
  20. └─b05fc2d00e4a Size: 24.96 kB (virtual 642.2 MB)
  21. └─c96a99614930 Size: 12.29 kB (virtual 642.2 MB)
  22. └─a6a357a48c49 Size: 12.29 kB (virtual 642.2 MB) Tags: ndj/mongodb:latest

docker images tree

import

  1. Usage: docker import URL|- [REPOSITORY[:TAG]]
  2. 创建一个空文件系统映像和引用压缩文件的内容
  3. (.tar, .tar.gz, .tgz, .bzip, .tar.xz, .txz) into it, 然后选择性的标记.

此时,这个URl必须指向一个文件存档(.tar, .tar.gz, .tgz, .bzip, .tar.xz, or .txz) 包含一个跟文件系统,如果你想引用一个本地的文件压缩文件,你可以使用从输入端使用参数

Examples

输入一个远程的地址

  1. sudo docker import http://example.com/exampleimage.tgz

你可以引用我的url速度快,http://docker.widuu.com/ubuntu.tar

输入一个本地的文件

通过管道输入docker

  1. cat exampleimage.tgz | sudo docker import - exampleimagelocal:new

docker import

注意本例子中 sudo 你必须保留文件的所有权(特别是root所有权)在tar文档,如果当你的tar不是root(或者 sudo 命令),那么所有权可能不会保留!

info

  1. Usage: docker info
  2. 显示整个文件系统
  3. $ sudo docker info
  4. Containers: 292
  5. Images: 194
  6. Debug mode (server): false
  7. Debug mode (client): false
  8. Fds: 22
  9. Goroutines: 67
  10. LXC Version: 0.9.0
  11. EventsListeners: 115
  12. Kernel Version: 3.8.0-33-generic
  13. WARNING: No swap limit support

docker info

本文由widuu贡献翻译,转载请注明来自http://www.widuu.com~