gyts62 发表于 2015-10-13 10:39:30

关于docker镜像

关于docker镜像,
镜像有一个repository的概念,非常好、可以自己建立自己用,也有开源贡献者,总体来说,目前大量用户使用的核心就是建立镜像,然后自己使用。。。
root@server-zyq9z8tu:~#docker images -h

Usage: dockerimages

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    OFFICIALAUTOMATED
sameersbn/redmine                                                                122               
tukiyo3/centos7-redmine                                                          2                  
redmine                        Redmine is a flexibleproject management w...1            
vpetersson/redmine                                                               1                  
melopos/redmine                                                                  1                  
marcelhuberfoo/redmine-plantuml                                                1                  
triangle/redmine-plugin-dev      Redmine 2.4.1 on ruby 2.0 aimed atplugin ...1                  
joshuacox/docker-redmine                                                         0                  
miraitechno/redmine                                                            0                  
ir2sora/redmine                                                                  0                  
viewpl/docker-redmine            Redmine container image based onphusion/b...0                  

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-x5 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-x2 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


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





提交image到docker hub


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


The push refers toa repository (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 (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:~#





删除rmi(remove 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,有点类似我们做snapshot,把当时的image id,设置tag,保存。


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





Usage: docker tag IMAGE 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


http://blog.iyunv.com/gnicky/article/details/






         版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: 关于docker镜像