docker镜像的创建和下载使用

首先查看已有的imags。 
root@helight-Xu:/data# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
debian latest 4d6ce913b130 3 days ago 84.98 MB
ubuntu latest b39b81afc8ca 3 days ago 188.3 MB
<none> <none> 8eaa4ff06b53 2 weeks ago 188.3 MB
这个在上一篇文章中介绍了如何下载已经提供的基础image包。http://zhwen.org/?p=876
ps命令可以查看已经运行过的容器,这些容器是由image创建的,有唯一的id标识。
root@helight-Xu:/data# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c13399fff6b ubuntu:latest “/bin/bash” 3 minutes ago Exited (0) 2 minutes ago admiring_pike
root@helight-Xu:/data# docker commit 2c13399fff6b xtodo
52858544b7aa4a05173c578cb12c954896e4797f17057bcab85e518b678cf6f3
root@helight-Xu:/data# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c13399fff6b ubuntu:latest “/bin/bash” 4 minutes ago Exited (0) 2 minutes ago admiring_pike
root@helight-Xu:/data# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
xtodo latest 52858544b7aa 6 seconds ago 191.1 MB
debian latest 4d6ce913b130 3 days ago 84.98 MB
ubuntu latest b39b81afc8ca 3 days ago 188.3 MB
<none> <none> 8eaa4ff06b53 2 weeks ago 188.3 MB
export(将文件系统的内容作为tar存档文件导出到STDOUT)
root@helight-Xu:/data# docker export 418fe2e3efdd >xtodo.tar
root@helight-Xu:/data# ll
-rw-r–r– 1 root root 200359424 1月 20 16:48 xtodo.tar
-rw-r–r– 1 helight helight 896924 7月 30 2013 xx.png
-rw-r–r– 1 helight helight 8385 12月 23 16:05 zhwen0.png
root@helight-Xu:/data# du -sh xtodo.tar
192M xtodo.tar
info命令可以查看目前物理主机的情况和docker创建的容器等信息
root@helight-Xu:/data# docker info
Containers: 11
Images: 12
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Dirs: 34
Execution Driver: native-0.2
Kernel Version: 3.11.0-26-generic
Operating System: Ubuntu 13.10
CPUs: 2
Total Memory: 3.615 GiB
Name: helight-Xu
ID: JWQJ:NH73:H5G6:X5MK:ZQQD:XPOW:XS5H:HYXM:63W3:VAE6:O5WA:ZZEL
WARNING: No swap limit support
root@helight-Xu:/data# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
xtodo latest 52858544b7aa 8 minutes ago 191.1 MB
debian latest 4d6ce913b130 3 days ago 84.98 MB
ubuntu latest b39b81afc8ca 3 days ago 188.3 MB
<none> <none> 8eaa4ff06b53 2 weeks ago 188.3 MB

import

创建一个空的文件系统映像,将打包文件[.tar、.tar.gz、.tgz、.bzip、.tar.xz或.txz]的内容导入到里面,然后以可选方式标记它。

docker import http://xx/xtodo.tar

从本地文件导入:

通过pipe和stdin导入到docker。

cat xtodo.tar  | sudo docker import – xtodo

从本地目录导入:

sudo tar -c . | sudo docker import – xtodo

Leave a Reply

Your email address will not be published. Required fields are marked *