S-Docker_02_基本概念_01_镜像
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了S-Docker_02_基本概念_01_镜像相关的知识,希望对你有一定的参考价值。
1.镜像:images search pull run -t -i commit build import save rmi load
1.1 列出镜像
docker images (列出本地已有镜像列表) 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 [email protected]:~# docker run -t -i ubuntu /bin/bash [email protected]:/# apt-get update (国外的可能比较慢) [email protected]:/# apt-get install vim [email protected]:/# vim /etc/apt/sources.list ....加入源 [email protected]:/#apt-get update (改完之后就很快) [email protected]:/#exit [email protected]:~# docker commit -m "added 163 mirrors" -a "docker new" f63998a68f59 ubuntu:v2_163 [email protected]:~# docker images 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服务的容器;
[email protected]:~/ljp/docker# mkdir -p ubuntu_lijp [email protected]:~/ljp/docker# cd ubuntu_lijp/ [email protected]:~/ljp/docker/ubuntu_lijp# vim Dockerfile #this is a docker FROM ubuntu:v2_163 MAINTAINER <[email protected]> RUN apt-get update RUN apt-get install -qqy apache2 [email protected]:~/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 <[email protected]> ---> Running in f7d56b23b140 ---> 2e796c9cd775 Removing intermediate container f7d56b23b140 Step 2 : RUN apt-get update ---> Running in 8fae114e67be .... [email protected]:~/ljp/docker/ubuntu_lijp# docker images 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 [email protected]:~/ljp/docker/ubuntu_lijp# docker run -t -i ubuntu:v3_apache2 /bin/bash [email protected]:/# /etc/init.d/apache2 start ... [email protected]:/# 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 [email protected]:/# 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 [email protected]:~# 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创建images的步骤演示出来了,有很多需要优化的地方,将在学习dockfile时集中学习;
1.6 镜像导入,导出
1.6.1
从本地镜像文件导入本地镜像库(https://openvz.org/Download/template/precreated)
[email protected]:~/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 [email protected]:~/ljp/docker# cat centos-6-x86_64.tar.gz | docker import - centos:6_v1 17d0130ca4cc7e644eb20e5052956973332bdd0c9ee23e79872d1859e2101f8d [email protected]:~/ljp/docker# docker images 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
从镜像导出到模板文件
[email protected]:~/ljp/docker# docker save -o ubuntu_14.04_apache2.tar ubuntu:v3_apache2 [email protected]:~/ljp/docker# ls centos-6-x86_64.tar.gzubuntu_14.04_apache2.tar ubuntu_lijp [email protected]:~/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 [email protected]:~/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
移除本地镜像
[email protected]:~/ljp/docker# docker rmi centos:6_v1 Untagged: centos:6_v1 Deleted: 17d0130ca4cc7e644eb20e5052956973332bdd0c9ee23e79872d1859e2101f8d [email protected]:~/ljp/docker# docker images 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 是见容器快照文件导入本地镜像库,快照文件没有历史记录和元数据信息,体积小,可以重新指定标签和元数据信息
本文出自 “lijp” 博客,请务必保留此出处http://jiapeng.blog.51cto.com/6706171/1739934
以上是关于S-Docker_02_基本概念_01_镜像的主要内容,如果未能解决你的问题,请参考以下文章
Java千百问_01基本概念(015)_阻塞非阻塞有什么区别