设为首页 收藏本站
查看: 1115|回复: 0

[经验分享] 关于docker镜像

[复制链接]

尚未签到

发表于 2015-10-13 10:39:30 | 显示全部楼层 |阅读模式
关于docker镜像,
镜像有一个repository的概念,非常好、可以自己建立自己用,也有开源贡献者,总体来说,目前大量用户使用的核心就是建立镜像,然后自己使用。。。
root@server-zyq9z8tu:~#docker images -h

Usage: dockerimages [OPTIONS] [NAME]

List images

-a, --all=false     Show all images (by default filter outthe intermediate image layers)
-f, --filter=[]     Provide filter values (i.e.'dangling=true')
--no-trunc=false    Don't truncate output
-q, --quiet=false   Only show numeric IDs


公共Image以及贡献排名、
root@server-zyq9z8tu:~#docker search redmine
NAME                             DESCRIPTION                                    STARS    OFFICIAL  AUTOMATED
sameersbn/redmine                                                                122                 [OK]
tukiyo3/centos7-redmine                                                          2                   [OK]
redmine                          Redmine is a flexibleproject management w...  1        [OK]      
vpetersson/redmine                                                               1                   [OK]
melopos/redmine                                                                  1                   [OK]
marcelhuberfoo/redmine-plantuml                                                  1                   [OK]
triangle/redmine-plugin-dev      Redmine 2.4.1 on ruby 2.0 aimed atplugin ...  1                   [OK]
joshuacox/docker-redmine                                                         0                   [OK]
miraitechno/redmine                                                              0                   [OK]
ir2sora/redmine                                                                  0                   [OK]
viewpl/docker-redmine            Redmine container image based onphusion/b...  0                   [OK]

docker pull
如何获取一个新的镜像。我们知道当我们运行一个镜像的时候,可以使用dockerpull拉取指令。

以上这些Image在本地的存放位置以及差异文件存放位置
/var/lib/docker/aufs/diff/c852f6d61e65cddf1e8af1f6cd7db78543bfb83cdcd36845541cf6d9dfef20a0/etc/centos-release
/var/lib/docker/aufs/diff/c852f6d61e65cddf1e8af1f6cd7db78543bfb83cdcd36845541cf6d9dfef20a0/etc/centos-release-upstream
/var/lib/docker/aufs/diff/c852f6d61e65cddf1e8af1f6cd7db78543bfb83cdcd36845541cf6d9dfef20a0/usr/share/centos-release
root@server-zyq9z8tu:~#cd /var/lib/docker/aufs/
root@server-zyq9z8tu:/var/lib/docker/aufs#ll
total 68
drwxr-xr-x  5 root root 4096 Aug 15 11:42 ./
drwx------  8 root root 4096 Aug 15 20:50 ../
drwxr-xr-x 206 rootroot 20480 Aug 15 20:50 diff/
drwxr-xr-x  2 root root 20480 Aug 15 20:50 layers/
drwxr-xr-x 206 rootroot 20480 Aug 15 20:50 mnt/

重点
一般用户最希望的就是Build一个自己的image然后觉得非常好用?维护这个image的版本,那么DockerFile就非常重要,vi编辑一个Dockerfile,提醒各位,测试而已不要用很强大费时的命令例如yum–y update
root@server-zyq9z8tu:~# docker build-t="robin/cupdate" ./
Sending build context to Docker daemon14.85 kB
Sending build context to Docker daemon
Step 0 : FROM centos
---> 7322fbe74aa5
Step 1 : MAINTAINER Robin
---> Running in d3891075f94b
---> 7332f13478e5
Removing intermediate containerd3891075f94b
Step 2 : RUN yum -y update
---> Running in eaa6d8a02b0f
Loaded plugins:fastestmirror
Vim Dockerfile
具体内容如下:
root@server-zyq9z8tu:~# cat Dockerfile
#comment for author
#by default use latest centos
FROM centos
MAINTAINER Robin
RUN yum -y install python
root@server-zyq9z8tu:~# docker build -t="robin/cupdate" ./
Sending build context to Docker daemon14.85 kB
Sending build context to Docker daemon
Step 0 : FROM centos
---> 7322fbe74aa5
Step 1 : MAINTAINER Robin
---> Using cache
---> 7332f13478e5
Step 2 : RUN yum -y install python
---> Running in 3ae4d9519080
Loaded plugins: fastestmirror
Determining fastest mirrors
*base: centos.ustc.edu.cn
*extras: centos.ustc.edu.cn
*updates: centos.ustc.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package python.x86_640:2.7.5-16.el7 will be updated
---> Package python.x86_640:2.7.5-18.el7_1.1 will be an update
--> Processing Dependency:python-libs(x86-64) = 2.7.5-18.el7_1.1 for package:python-2.7.5-18.el7_1.1.x86_64
--> Running transaction check
---> Package python-libs.x86_640:2.7.5-16.el7 will be updated
---> Package python-libs.x86_640:2.7.5-18.el7_1.1 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package           Arch         Version                 Repository     Size
================================================================================
Updating:
python            x86_64       2.7.5-18.el7_1.1        updates        86 k
Updating for dependencies:
python-libs       x86_64       2.7.5-18.el7_1.1        updates       5.6M

Transaction Summary
================================================================================
Upgrade 1 Package (+1 Dependent package)

Total download size: 5.7 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpmnot installed.
warning:/var/cache/yum/x86_64/7/updates/packages/python-2.7.5-18.el7_1.1.x86_64.rpm:Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key forpython-2.7.5-18.el7_1.1.x86_64.rpm is not installed
--------------------------------------------------------------------------------
Total                                              12 MB/s | 5.7 MB 00:00   
Retrieving key fromfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid    : &quot;CentOS-7 Key (CentOS 7 Official Signing Key)<security@centos.org>&quot;
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb124c6 a8a7 f4a8 0eb5
Package   : centos-release-7-1.1503.el7.centos.2.8.x86_64 (@CentOS)
From      : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating  :python-libs-2.7.5-18.el7_1.1.x86_64                         1/4
Updating  :python-2.7.5-18.el7_1.1.x86_64                              2/4
Cleanup   :python-2.7.5-16.el7.x86_64                                  3/4
Cleanup   :python-libs-2.7.5-16.el7.x86_64                             4/4
Verifying :python-2.7.5-18.el7_1.1.x86_64                              1/4
Verifying :python-libs-2.7.5-18.el7_1.1.x86_64                         2/4
Verifying :python-libs-2.7.5-16.el7.x86_64                             3/4
Verifying :python-2.7.5-16.el7.x86_64                                  4/4

Updated:
python.x86_64 0:2.7.5-18.el7_1.1                                             

Dependency Updated:
python-libs.x86_64 0:2.7.5-18.el7_1.1                                       

Complete!
---> c292febcc2ad
Removing intermediatecontainer 3ae4d9519080
Successfully builtc292febcc2ad

注意以上的输出,container的编号已经给出了
root@server-zyq9z8tu:~# docker images |grepc292*
robin/cupdate      latest               c292febcc2ad       2 minutes ago      270MB
----- ----- ---- ---- ---- ---- ----- ----






root@server-zyq9z8tu:~#docker images


REPOSITORY   TAG    IMAGEID           CREATED            VIRTUALSIZE


robin/cupdate latest       c292febcc2ad       24hours ago       270 MB


ubuntu      wily         1832625b2be3       8days ago         133 MB


ubuntu    wily-20150807        1832625b2be3       8days ago         133 MB


ubuntu    15.10                1832625b2be3       8days ago         133 MB


ubuntu    trusty               8251da35e7a7       8days ago         188.4 MB


ubuntu    latest               8251da35e7a7       8days ago         188.4 MB


ubuntu    14.04                8251da35e7a7       8days ago         188.4 MB


ubuntu 14.04.3              8251da35e7a7       8days ago         188.4 MB


ubuntu   trusty-20150806      8251da35e7a7       8days ago         188.4 MB


ubuntu wily-20150731        6767f35d9be6       11days ago        134.8 MB


ubuntu vivid-20150802       23635bbeb7c5       11days ago        131.3 MB


ubuntu   vivid                23635bbeb7c5       11days ago        131.3 MB


ubuntu 15.04                23635bbeb7c5       11days ago        131.3 MB


imagesize真是很小,然后很容易下载几个package就上来了





提交imagedocker hub


root@server-zyq9z8tu:~#docker push robin/cupdate


The push refers toa repository [robin/cupdate] (len: 1)


Sending image list


按步骤输入在DockerHub注册的用户名、密码和邮箱即可完成.


Please login priorto push:


Username: abbroot


Password:


Email:lugnicky@163.com


Account created.Please use the confirmation link we sent to your e-mailto activate it.


The push refers toa repository [robin/cupdate] (len: 1)


Sending image list


2015/08/16 21:57:48Error: Status 403 trying to push repository robin/cupdate: Account is notActive


root@server-zyq9z8tu:~#





删除rmiremove image


root@server-zyq9z8tu:~#docker rmi centos


Untagged:centos:latest


root@server-zyq9z8tu:~#docker images |grep centos*


确认已没有存在


======= ============= ======= ===== ===通配符操作


root@server-zyq9z8tu:~#docker rmi centos:*


Error response fromdaemon: No such image: centos:*


2015/08/16 22:03:45Error: failed to remove one or more images


root@server-zyq9z8tu:~#docker rmi centos*


Error response fromdaemon: No such image: centos*


2015/08/16 22:03:56Error: failed to remove one or more images


设立Tag,有点类&#20284;我们做snapshot,把当时的image id,设置tag,保存。


root@server-zyq9z8tu:~#docker tag -h





Usage: docker tag[OPTIONS] IMAGE [REGISTRYHOST/][USERNAME/]NAME[:TAG]





Tag an image into arepository





  -f, --force=false   Force





按照以下步骤,我们在安装不确定软件前,实施了Tag操作,然后我们继续在latest image操作


root@server-zyq9z8tu:~#docker tag c292febcc2ad robin/cupdate:vruby


root@server-zyq9z8tu:~#docker images


REPOSITORY         TAG                  IMAGE ID           CREATED             VIRTUAL SIZE


robin/cupdate      latest               c292febcc2ad       24 hours ago        270 MB


robin/cupdate      vruby                c292febcc2ad       24 hours ago       270 MB


ubuntu             15.10                1832625b2be3       8 days ago          133 MB


ubuntu             wily-20150807        1832625b2be3       8 days ago          133 MB


可以多进程的docker exec









&#65279;&#65279;&#65279;&#65279;         版权声明:本文为博主原创文章,未经博主允许不得转载。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-126195-1-1.html 上篇帖子: docker科普 下篇帖子: 在 CentOS 6.x上安装 docker.io成功
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表