1.镜像:p_w_picpaths search pull run -t -i commit build import save rmi load
1.1 列出镜像
docker p_w_picpaths (列出本地已有镜像列表) REPOSITORY(所在仓库) TAG(标记) IMAGE ID(唯一ID号) CREATE(创建时间) VIRTUAL SIZE(镜像大小)
1.2 搜索镜像
docker search 镜像名
1.3 下载镜像
docker pull 镜像名 (默认在docker hub中下载) docker pull IP/域名:5000/镜像名 dl.dockerpool.com:5000/ubuntu:12.04 具体请参考http://dockerpool.com/
1.4 修改镜像_01(docker commit)
1.4.1
镜像默认使用的国外的的源,修改成国内的源,如morris.163.com root@vmc01:~# docker run -t -i ubuntu /bin/bash root@f63998a68f59:/# apt-get update (国外的可能比较慢) root@f63998a68f59:/# apt-get install vim root@f63998a68f59:/# vim /etc/apt/sources.list ....加入源 root@f63998a68f59:/#apt-get update (改完之后就很快) root@f63998a68f59:/#exit root@vmc01:~# docker commit -m "added 163 mirrors" -a "docker new" f63998a68f59 ubuntu:v2_163 root@vmc01:~# docker p_w_picpaths REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu v2_163 8c525f0bec06 8 seconds ago 263 MB debian latest d4b2ba78e3b4 3 weeks ago 125.1 MB ubuntu latest af88597ec24b 3 weeks ago 187.9 MB
1.5 修改镜像_02(docker build)
1.5.1
docker commit 扩展镜像适合个人使用,相比较,使用dockfile 创建镜像更方便,易于共享;
1.5.2
比如我通过Dockerfile 来创建一个可以提供http服务的容器;
root@vmc01:~/ljp/docker# mkdir -p ubuntu_lijp root@vmc01:~/ljp/docker# cd ubuntu_lijp/ root@vmc01:~/ljp/docker/ubuntu_lijp# vim Dockerfile #this is a docker FROM ubuntu:v2_163 MAINTAINER <lijp@act.buaa.edu.cn> RUN apt-get update RUN apt-get install -qqy apache2 root@vmc01:~/ljp/docker/ubuntu_lijp# docker build -t="ubuntu:v3_apache2" /root/ljp/docker/ubuntu_lijp/ Sending build context to Docker daemon 2.048 kB Sending build context to Docker daemon Step 0 : FROM ubuntu:v2_163 ---> 8c525f0bec06 Step 1 : MAINTAINER <lijp@act.buaa.edu.cn> ---> Running in f7d56b23b140 ---> 2e796c9cd775 Removing intermediate container f7d56b23b140 Step 2 : RUN apt-get update ---> Running in 8fae114e67be .... root@vmc01:~/ljp/docker/ubuntu_lijp# docker p_w_picpaths REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu v3_apache2 71f2b7fb0272 50 seconds ago 300.1 MB ubuntu v2_163 8c525f0bec06 44 minutes ago 263 MB debian latest d4b2ba78e3b4 3 weeks ago 125.1 MB ubuntu latest af88597ec24b 3 weeks ago 187.9 MB root@vmc01:~/ljp/docker/ubuntu_lijp# docker run -t -i ubuntu:v3_apache2 /bin/bash root@6094bbf8d1d7:/# /etc/init.d/apache2 start ... root@6094bbf8d1d7:/# netstat -antp Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp6 0 0 :::80 :::* LISTEN 54/apache2 root@6094bbf8d1d7:/# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:0d inet addr:172.17.0.13 Bcast:0.0.0.0 Mask:255.255.0.0 root@vmc01:~# curl 172.17.0.13 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> ... 上面步骤完整将使用dockerfile创建p_w_picpaths的步骤演示出来了,有很多需要优化的地方,将在学习dockfile时集中学习;
1.6 镜像导入,导出
1.6.1
从本地镜像文件导入本地镜像库(https://openvz.org/Download/template/precreated)
root@vmc01:~/ljp/docker# ls -lh total 219M -rw-r--r-- 1 root root 219M Jan 29 12:12 centos-6-x86_64.tar.gz drwxr-xr-x 2 root root 4.0K Jan 29 11:44 ubuntu_lijp root@vmc01:~/ljp/docker# cat centos-6-x86_64.tar.gz | docker import - centos:6_v1 17d0130ca4cc7e644eb20e5052956973332bdd0c9ee23e79872d1859e2101f8d root@vmc01:~/ljp/docker# docker p_w_picpaths REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos 6_v1 17d0130ca4cc 32 seconds ago 612 MB ubuntu v3_apache2 71f2b7fb0272 41 minutes ago 300.1 MB ubuntu v2_163 8c525f0bec06 About an hour ago 263 MB debian latest d4b2ba78e3b4 3 weeks ago 125.1 MB ubuntu latest af88597ec24b 3 weeks ago 187.9 MB
1.6.2
从镜像导出到模板文件
root@vmc01:~/ljp/docker# docker save -o ubuntu_14.04_apache2.tar ubuntu:v3_apache2 root@vmc01:~/ljp/docker# ls centos-6-x86_64.tar.gzubuntu_14.04_apache2.tar ubuntu_lijp root@vmc01:~/ljp/docker# ls -lh total 517M -rw-r--r-- 1 root root 219M Jan 29 12:12 centos-6-x86_64.tar.gz -rw-r--r-- 1 root root 298M Jan 29 12:23 ubuntu_14.04_apache2.tar drwxr-xr-x 2 root root 4.0K Jan 29 11:44 ubuntu_lijp root@vmc01:~/ljp/docker# 1.6.3
导入的其他方式
docker load --input centos-6-x86_64.tar.gz docker load < centos-6-x86_64.tar.gz #将导入镜像以及其相关的元数据信息(包括标签等)
1.6.4
移除本地镜像
root@vmc01:~/ljp/docker# docker rmi centos:6_v1 Untagged: centos:6_v1 Deleted: 17d0130ca4cc7e644eb20e5052956973332bdd0c9ee23e79872d1859e2101f8d root@vmc01:~/ljp/docker# docker p_w_picpaths REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu v3_apache2 71f2b7fb0272 59 minutes ago 300.1 MB ubuntu v2_163 8c525f0bec06 About an hour ago 263 MB debian latest d4b2ba78e3b4 3 weeks ago 125.1 MB ubuntu latest af88597ec24b 3 weeks ago 187.9 MB #移除镜像需要预先删除依赖于此镜像的容器docker rm
###镜像导入docker import 与 docker load 的区别:
1.load 是将整个镜像存储文件导入本地镜像库,记录完整,体积大
2.import 是见容器快照文件导入本地镜像库,快照文件没有历史记录和元数据信息,体积小,可以重新指定标签和元数据信息
转载于:https://blog.51cto.com/jiapeng/1739934