• 阿里云部署Docker(5)----管理和公布您的镜像


    出到这节,我在百度搜索了一下“阿里云部署Docker”,突然发现怎么会有人跟我写的一样呢?哦,原来是其它博客系统的爬虫来抓取,然后也不会写转载自什么什么的。所以,我最终明确为什么那些大咖的文章总会在文章的开头写明,转载请注明原创来自xxx的。恩。get it,从这篇開始,我也要这样了。

    本文欢迎转载,但要尊重本人劳动成果,转载注明转自“http://blog.csdn.net/minimicall/” http://blog.csdn.net/minimicall/article/details/40147207

    对阿里云里面部署Docker,我的之前的文章有:

    第一篇,安装篇:http://blog.csdn.net/minimicall/article/details/40108305

    第二篇,依然是安装:http://blog.csdn.net/minimicall/article/details/40119177

    第三篇,基础指令学习:http://blog.csdn.net/minimicall/article/details/40143061

    第四篇,容器的使用:http://blog.csdn.net/minimicall/article/details/40144719


    今天,我们要进一步解说,

    管理本地镜像

    创建基础镜像

    上传公布镜像

    Listing images on the host

    我们首先通过 docker images来查看一下我们本地有什么镜像。

    root@iZ28ikebrg6Z:~# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    ubuntu              utopic              2185fd50e2ca        2 days ago          237.2 MB
    ubuntu              14.10               2185fd50e2ca        2 days ago          237.2 MB
    ubuntu              trusty              9cbaf023786c        2 days ago          192.8 MB
    ubuntu              14.04               9cbaf023786c        2 days ago          192.8 MB
    ubuntu              14.04.1             9cbaf023786c        2 days ago          192.8 MB
    ubuntu              latest              9cbaf023786c        2 days ago          192.8 MB
    ubuntu              12.04.5             a9561eb1b190        2 days ago          120.2 MB
    ubuntu              precise             a9561eb1b190        2 days ago          120.2 MB
    ubuntu              12.04               a9561eb1b190        2 days ago          120.2 MB
    centos              latest              87e5b6b3ccc1        2 weeks ago         224 MB
    ubuntu              12.10               c5881f11ded9        3 months ago        172.2 MB
    ubuntu              quantal             c5881f11ded9        3 months ago        172.2 MB
    ubuntu              13.04               463ff6be4238        3 months ago        169.4 MB
    ubuntu              raring              463ff6be4238        3 months ago        169.4 MB
    ubuntu              saucy               195eb90b5349        3 months ago        184.7 MB
    ubuntu              13.10               195eb90b5349        3 months ago        184.7 MB
    training/webapp     latest              31fa814ba25a        4 months ago        278.8 MB
    ubuntu              lucid               3db9c44f4520        5 months ago        183 MB
    ubuntu              10.04               3db9c44f4520        5 months ago        183 MB
    能够看到,我在之前的教程里面拉取了两个一个是ubuntu,一个是training/webapp。当中ubuntu,docker给我拉取了那么多变种回来。上面的输出有一列叫“TAG”,记得我们执行的时候会有"docker run ubuntu:14.04 /bin/bash 么 !就是依据TAG来精确的指定我们想要执行的那个ubuntu,否则docker会自作聪明的执行TAG为“latest”的那个镜像。

    Getting a new image


    怎样获取一个新的镜像。我们知道当我们执行一个镜像的时候,假设这个镜像比如centos在本地没有,docker会自己主动的去远端库查询和下载。可是这样的暂时的下载明显是费时间的,我们能够不能够提前去下载呢?能够,使用docker pull拉取指令。

    root@iZ28ikebrg6Z:~# docker pull centos
    Pulling repository centos
    ^Croot@iZ28ikebrg6Z:~# ^C
    你看,它会去拉取,只是我中断了,由于我不须要,我的阿里云存储非常金贵的。

    Finding images

    搜索一个镜像,你能够选择去docker hub的站点搜索,也能够选择在本地用命令行的方式进行。

    例如以下:

    root@iZ28ikebrg6Z:~# docker search redmine
    NAME                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
    sameersbn/redmine                                                              40                   [OK]
    webts/redmine                  Self contained Redmine 2.4 install on Cent...   2                    
    triangle/redmine-plugin-dev    Redmine 2.4.1 on ruby 2.0 aimed at plugin ...   1                    [OK]
    oasis/redmine-git                                                              1                    
    melopos/redmine                                                                1                    [OK]
    turnkeylinux/redmine-13.0      TurnKey Redmine - Integrated SCM & Project...   1                    
    sherkenh/redmine                                                               0                    
    oasis/redmine                                                                  0                    
    bernigaud/redmine              Redmine for my server HAL Forked from same...   0                    
    eprecise/redmine                                                               0                    
    hogefoobar/redmine                                                             0                    
    mattuso/redmine_nginx                                                          0                    [OK]
    mattuso/redmine_mysql                                                          0                    [OK]
    aofox5152/redmine                                                              0                    
    chonglou/redmine               remine+mysql+nginx                              0                    
    laughk/redmine                                                                 0                    
    krickwix/redmine                                                               0                    
    bazitov/redmine                                                                0                    
    sasasin/redmine-scrum          ALMinium on CentOS 6, with SSH server.          0                    
    yjkim/apache-redmine                                                           0                    
    sosyco/redmine-sqlite-debian   Tryout/GetAndRun  Redmine 2.5.1/sqlitel/De...   0                    
    eternnoir/redminebot                                                           0                    [OK]
    sosyco/redmine-mysql-debian     Tryout/GetAndRun Redmine 2.5.1/mysql/Debi...   0                    
    hiromiso/redmine2.4            redmine + mysql                                 0                    
    tmtkd/redminetest              Sep. 1st, 2014 test of redmine/docker           0                    
    pvdvreede/redminedev           Installation of ruby 2.0.0-p247 and others      0                    
    madmaze/ubunturedmine          quick ubuntu 12.04 image with Redmine on s...   0                    
    shaftoe/new_redmine            WARNING: old legacy Redmine, not usable fo...   0                    
    mattuso/redmine_unicorn                                                        0                    [OK]
    vpetersson/redmine                                                             0                    [OK]
    miraitechno/redmine                                                            0                    [OK]
    pnelson/redmine                                                                0                    [OK]
    padelt/redmine                                                                 0                    [OK]
    binaryphile/redmine            Reusable, general-purpose Redmine instance...   0 

    我们搜索了一下redmine,这是个项目管理的服务。上面的列 有,名字,描写叙述,星级(越流行评分越高,提供參考),是否有官方维护,是否自己主动化,这点我不是非常能理解,我也不敢误人子弟。所以还是引用官网的那句话,各位看官自己理解

    Official repositories are built and maintained by the Stackbrew project, and Automated repositories are Automated Builds that allow you to validate the source and content of an image.

    选一个pull下来即可了。

    Building an image from a Dockerfile

    通过Dockerfile来构建一个镜像。用vim写一个Dockerfile,内如例如以下:

    #This is a comment
    FROM ubuntu:14.04
    MAINTAINER zengjinlong <470910357@qq.com>
    RUN apt-get update && apt-get install -y ruby ruby-dev
    RUN gem install sinatra

    命令都是大写,FROM表示它的源是什么,比如我们这个是给予Ubuntu:14.04的,MAINTANER是维护人员,比方说我,小曾,卖下萌。

    RUN表示运行指令。

    好,运行上述Dockerfile。

    root@iZ28ikebrg6Z:~/docker# docker build -t="zengjinlong/sinatra:v2" .
    Sending build context to Docker daemon  2.56 kB
    Sending build context to Docker daemon 
    Step 0 : FROM ubuntu:14.04
     ---> 9cbaf023786c
    Step 1 : MAINTAINER zengjinlong <470910357@qq.com>
     ---> Running in c5674e71d7e4
     ---> 224b40d4b89f
    Removing intermediate container c5674e71d7e4
    Step 2 : RUN apt-get update && apt-get install -y ruby ruby-dev
     ---> Running in 5d6373cb79e6
    Ign http://archive.ubuntu.com trusty InRelease
    Ign http://archive.ubuntu.com trusty-updates InRelease
    Ign http://archive.ubuntu.com trusty-security InRelease
    Ign http://archive.ubuntu.com trusty-proposed InRelease
    Get:1 http://archive.ubuntu.com trusty Release.gpg [933 B]
    Get:2 http://archive.ubuntu.com trusty-updates Release.gpg [933 B]
    Get:3 http://archive.ubuntu.com trusty-security Release.gpg [933 B]
    Get:4 http://archive.ubuntu.com trusty-proposed Release.gpg [933 B]
    Get:5 http://archive.ubuntu.com trusty Release [58.5 kB]
    Get:6 http://archive.ubuntu.com trusty-updates Release [59.7 kB]
    Get:7 http://archive.ubuntu.com trusty-security Release [59.7 kB]
    Get:8 http://archive.ubuntu.com trusty-proposed Release [110 kB]
    Get:9 http://archive.ubuntu.com trusty/main Sources [1335 kB]
    

    会耗费比較长的时间。

    我们技术下一步的学习。

    标记一个image

    docker tag 5db5f8471261 ouruser/sinatra:devel
    root@iZ28ikebrg6Z:~/docker# docker tag   224b40d4b89f  zengjinlong/sinatra:v3

    结果显示一下,

    输出:

    root@iZ28ikebrg6Z:~/docker# docker images
    REPOSITORY            TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    <strong><span style="color:#ff0000;">zengjinlong/sinatra   v3           </span></strong>       224b40d4b89f        13 minutes ago      192.8 MB
    ubuntu                14.10               2185fd50e2ca        2 days ago          237.2 MB
    ubuntu                utopic              2185fd50e2ca        2 days ago          237.2 MB
    ubuntu                trusty              9cbaf023786c        2 days ago          192.8 MB
    ubuntu                latest              9cbaf023786c        2 days ago          192.8 MB
    ubuntu                14.04.1             9cbaf023786c        2 days ago          192.8 MB
    ubuntu                14.04               9cbaf023786c        2 days ago          192.8 MB
    ubuntu                precise             a9561eb1b190        2 days ago          120.2 MB
    ubuntu                12.04.5             a9561eb1b190        2 days ago          120.2 MB
    ubuntu                12.04               a9561eb1b190        2 days ago          120.2 MB
    centos                centos5             504a65221a38        2 weeks ago         467.1 MB
    centos                centos6             68edf809afe7        2 weeks ago         212.7 MB
    centos                centos7             87e5b6b3ccc1        2 weeks ago         224 MB
    centos                latest              87e5b6b3ccc1        2 weeks ago         224 MB
    ubuntu                quantal             c5881f11ded9        3 months ago        172.2 MB
    ubuntu                12.10               c5881f11ded9        3 months ago        172.2 MB
    ubuntu                13.04               463ff6be4238        3 months ago        169.4 MB
    ubuntu                raring              463ff6be4238        3 months ago        169.4 MB
    ubuntu                saucy               195eb90b5349        3 months ago        184.7 MB
    ubuntu                13.10               195eb90b5349        3 months ago        184.7 MB
    training/webapp       latest              31fa814ba25a        4 months ago        278.8 MB
    ubuntu                10.04               3db9c44f4520        5 months ago        183 MB
    ubuntu                lucid               3db9c44f4520        5 months ago        183 MB

    上传我们的镜像到docker hub里面。

    root@iZ28ikebrg6Z:~/docker# docker push zengjinlong/sinatra
    The push refers to a repository [zengjinlong/sinatra] (len: 1)
    Sending image list
    ^Croot@iZ28ikebrg6Z:~/docker# 

    演示一下就OK,不是非常想在这里浪费时间。

    删除本地镜像,由于毕竟占地方把。

    root@iZ28ikebrg6Z:~/docker# docker rmi centos
    Untagged: centos:latest
    root@iZ28ikebrg6Z:~/docker# docker images
    REPOSITORY            TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    zengjinlong/sinatra   v3                  224b40d4b89f        18 minutes ago      192.8 MB
    ubuntu                14.10               2185fd50e2ca        2 days ago          237.2 MB
    ubuntu                utopic              2185fd50e2ca        2 days ago          237.2 MB
    ubuntu                14.04               9cbaf023786c        2 days ago          192.8 MB
    ubuntu                latest              9cbaf023786c        2 days ago          192.8 MB
    ubuntu                trusty              9cbaf023786c        2 days ago          192.8 MB
    ubuntu                14.04.1             9cbaf023786c        2 days ago          192.8 MB
    ubuntu                12.04.5             a9561eb1b190        2 days ago          120.2 MB
    ubuntu                12.04               a9561eb1b190        2 days ago          120.2 MB
    ubuntu                precise             a9561eb1b190        2 days ago          120.2 MB
    centos                centos5             504a65221a38        2 weeks ago         467.1 MB
    centos                centos6             68edf809afe7        2 weeks ago         212.7 MB
    centos                centos7             87e5b6b3ccc1        2 weeks ago         224 MB
    ubuntu                12.10               c5881f11ded9        3 months ago        172.2 MB
    ubuntu                quantal             c5881f11ded9        3 months ago        172.2 MB
    ubuntu                raring              463ff6be4238        3 months ago        169.4 MB
    ubuntu                13.04               463ff6be4238        3 months ago        169.4 MB
    ubuntu                saucy               195eb90b5349        3 months ago        184.7 MB
    ubuntu                13.10               195eb90b5349        3 months ago        184.7 MB
    training/webapp       latest              31fa814ba25a        4 months ago        278.8 MB
    ubuntu                lucid               3db9c44f4520        5 months ago        183 MB
    ubuntu                10.04               3db9c44f4520        5 months ago        183 MB
    root@iZ28ikebrg6Z:~/docker# docker rmi centos:*
    Error response from daemon: No such image: centos:*
    2014/10/16 15:38:58 Error: failed to remove one or more images
    root@iZ28ikebrg6Z:~/docker# docker rmi centos
    Error response from daemon: No such image: centos:latest
    2014/10/16 15:39:03 Error: failed to remove one or more images
    root@iZ28ikebrg6Z:~/docker# 

    看来出了latest能够直接删除,其它的须要带上TAG才干指定删除。

    好今天到这里。






  • 相关阅读:
    Mkdocs文档生成
    IntelliJ IDEA
    WPS中页眉设置
    ubuntu下的画图工具-dia
    接口测试详细过程
    ubuntu下安装jmeter
    互联网产品接入支付功能如何测试?
    Uiautomator自动化测试编写和调试
    Ubuntu下配置android环境
    UIAutomator环境配置与运行
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4056824.html
Copyright © 2020-2023  润新知