下载一个 CentOS 的镜像:



# docker pull centos:``7.2``.``1511

下载完成后,使用命令查看本地镜像列表:

docker images centos


[root@localhost docker]#  docker images centos
<div style="background-color: inherit;">
    REPOSITORY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IMAGE&nbsp;ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CREATED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SIZE
</div>

<div style="background-color: inherit;">
    docker.io/centos&nbsp;&nbsp;&nbsp;&nbsp;7.2.1511&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#ff0000" style="background-color: inherit;">6866</font>72a1d0cc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6&nbsp;weeks&nbsp;ago&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;194.6&nbsp;MB
</div>


 

进入 docker run -i -t centos:7.2.1511 /bin/bash

或者docker run -i -t  6866 /bin/bash

 

比如 安装ssh和一些软件,上传一些工具,安装jdk等 


 
<div style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">
    <span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="background-color: inherit;"><span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">&nbsp;</span><span style="color: rgb(68, 68, 68); font-family: Tahoma, &quot;Microsoft Yahei&quot;, Simsun; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">替换系统默认时区</span></span></span></span>
</div>

<div style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">
    <span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="background-color: inherit;">rm -rf /etc/localtime</span></span></span>
</div>

<div style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">
    <span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="background-color: inherit;">ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime&nbsp;</span></span></span>
</div>

<div style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">
    <span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="background-color: inherit;">cat &gt; /etc/sysconfig/clock &lt;&lt;EOF</span></span></span>
</div>

<div style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">
    <span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="background-color: inherit;">ZONE=&quot;Asia/Shanghai&quot;</span></span></span>
</div>

<div style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">
    <span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="background-color: inherit;">UTC=<span style="background-color: inherit;">false</span></span></span></span>
</div>

<div style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">
    <span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="background-color: inherit;">EO</span><span style="background-color: inherit;">F</span></span></span>
</div>

    <span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: Simsun; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">#echo -e &quot;LANG=\&quot;en_US.UTF-8\&quot;&quot; &gt; /etc/default/local</span></span></span>


#mkdir /data


# mkdir /opt/tools



#yum -y install epel-release



总之-自定义自己想要的
    <span style="text-align: left; color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">改好了后</span>`<font size="3">exit</font>`<span style="text-align: left; color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">退出来</span>

<div style="background-color: inherit;">
    <font color="#333333" face="Helvetica Neue, Helvetica, Arial, PingFang SC, Hiragino Sans GB, WenQuanYi Micro Hei, Microsoft Yahei, sans-serif" style="background-color: inherit;"><span style="text-align: left; color: rgb(0, 0, 0); font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">查看正在运行的容器 :</span></font><span style="line-height: 1.5; background-color: inherit;">docker&nbsp;ps&nbsp;-l</span>

    <div style="background-color: inherit;">
        <span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="text-align: left; color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">然后</span>`docker commit &lt;container ID&gt; 新的镜像名`<span style="text-align: left; color: rgb(51, 51, 51); font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">来提交你的镜像</span></span>
    </div>

    <div style="background-color: inherit;">
        <div style="background-color: inherit;">
            #docker&nbsp;commit&nbsp;1a84d337ba4e&nbsp;&nbsp;centos7.2.1511-v1
        </div>
    </div>

    <div style="background-color: inherit;">
        <span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);"><span style="color: rgb(0, 0, 0); font-family: simsun; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(245, 248, 253);">如果不加冒号tag,默认的tag就是latest</span></span>
    </div>

    <div style="background-color: inherit;">
        <span style="font: 14px/21px simsun; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; float: none; display: inline !important; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: rgb(245, 248, 253); -webkit-text-stroke-width: 0px;">举例加个</span><span style="font: 14px/21px simsun; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: rgb(245, 248, 253); -webkit-text-stroke-width: 0px;">tag</span>
    </div>
</div>

<div style="background-color: inherit;">
    <div style="background-color: inherit;">
        #&nbsp;docker&nbsp;commit&nbsp;1a84d337ba4e&nbsp;&nbsp;centos7.2.1511-v2:centos7.2.1511-0815
    </div>
</div>

<div style="background-color: inherit;">
    <font face="simsun" style="background-color: inherit;">看一下镜像</font>
</div>

<div style="background-color: inherit;">
    <div style="background-color: inherit;">
        [root@localhost&nbsp;docker]#<font color="#ff0000" style="background-color: inherit;">&nbsp;docker&nbsp;images&nbsp;centos*</font>
    </div>

    <div style="background-color: inherit;">
        REPOSITORY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IMAGE&nbsp;ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CREATED&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SIZE
    </div>

    <div style="background-color: inherit;">
        centos7.2.1511-v2&nbsp;&nbsp;&nbsp;centos7.2.1511-0815&nbsp;&nbsp;&nbsp;dce617616993&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;30&nbsp;seconds&nbsp;ago&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;608.4&nbsp;MB
    </div>

    <div style="background-color: inherit;">
        centos7.2.1511-v1&nbsp;&nbsp;&nbsp;latest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f0410b352d06&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;30&nbsp;minutes&nbsp;ago&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;608.4&nbsp;MB
    </div>

    <div style="background-color: inherit;">
        docker.io/centos&nbsp;&nbsp;&nbsp;&nbsp;latest&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;970633036444&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2&nbsp;weeks&nbsp;ago&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;196.7&nbsp;MB
    </div>
</div>

<div style="background-color: inherit;">
    &nbsp;
</div>

<div style="background-color: inherit;">
    进入检查一下,是否成功
</div>

    <span style="background-color: inherit;">#<span style="text-align: left; color: rgb(0, 0, 0); font-family: 微软雅黑; font-size: 14px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">docker&nbsp;run&nbsp;-i&nbsp;-t</span></span><span style="background-color: inherit;">&nbsp;</span><span style="line-height: 1.5; background-color: inherit;">dce617616993&nbsp;</span><span style="line-height: 1.5; background-color: inherit;">&nbsp;/bin/bash</span>


exit


 
<div style="font: 14px/21px 微软雅黑; text-align: left; color: rgb(0, 0, 0); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;">
    最后,选择删除旧版本image---选配
</div>