www.icesr.com
IT运维工程师的摇篮

docker镜像管理命令学习

查看当前镜像

<code>[root@ztydl ~]<span class="hljs-preprocessor"># docker images</span>
REPOSITORY                              TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos-wget                             latest              <span class="hljs-number">9e694366</span>ecc0        <span class="hljs-number">29</span> minutes ago      <span class="hljs-number">312.9</span> MB
centos                                  latest              <span class="hljs-number">1</span>c1b67b33c28        <span class="hljs-number">3</span> weeks ago         <span class="hljs-number">196.6</span> MB
daocloud<span class="hljs-preprocessor">.io</span>/centos                      <span class="hljs-number">7</span>                   <span class="hljs-number">1</span>c1b67b33c28        <span class="hljs-number">3</span> weeks ago         <span class="hljs-number">196.6</span> MB
zty                                     latest              <span class="hljs-number">32e90</span>b4dd628        <span class="hljs-number">3</span> weeks ago         <span class="hljs-number">108.3</span> MB
daocloud<span class="hljs-preprocessor">.io</span>/daocloud/daocloud-toolset   latest              <span class="hljs-number">2</span>a2ecdfa41dc        <span class="hljs-number">6</span> months ago        <span class="hljs-number">147.1</span> MB</code>

根据镜像ID删除镜像(-f force 强行删除)

<code>[root@ztydl ~]<span class="hljs-preprocessor"># docker rmi 32e90b4dd628</span>
<span class="hljs-keyword">Error</span> response <span class="hljs-keyword">from</span> daemon: Conflict, cannot delete image <span class="hljs-number">32e90</span>b4dd628 because it <span class="hljs-keyword">is</span> tagged <span class="hljs-keyword">in</span> multiple repositories, use -f <span class="hljs-keyword">to</span> force
<span class="hljs-keyword">Error</span>: failed <span class="hljs-keyword">to</span> remove images: [<span class="hljs-number">32e90</span>b4dd628]</code>

搜索docker镜像

<code>[root<span class="hljs-variable">@ztydl</span> ~]<span class="hljs-comment"># docker search nginx</span></code>

根据镜像名下载 镜像

<code>[root<span class="hljs-variable">@ztydl</span> ~]<span class="hljs-comment"># docker pull nginx</span></code>

根据镜像ID给镜像打标签

<code>[root<span class="hljs-variable">@ztydl</span> ~]<span class="hljs-comment"># docker tag 1c1 centos</span></code>

运行docker镜像

<code>[root<span class="hljs-variable">@ztydl</span> ~]<span class="hljs-comment"># docker run -it centos /bin/bash</span>
[root<span class="hljs-variable">@ac14ee1c187c</span> /]<span class="hljs-comment"># ls</span>
anaconda-post.<span class="hljs-keyword">log</span>  dev  home  lib64       media  opt   root  sbin  sys  usr
bin                etc  lib   lost+found  mnt    proc  run   srv   tmp  var</code>

查看正在运行的容器

<code>[root<span class="hljs-variable">@ztydl</span> ~]<span class="hljs-comment"># docker ps</span></code>

查看左右容器

<code>[root<span class="hljs-variable">@ztydl</span> ~]<span class="hljs-comment"># docker ps -a</span>
<span class="hljs-constant">CONTAINER</span> <span class="hljs-constant">ID</span>        <span class="hljs-constant">IMAGE</span>               <span class="hljs-constant">COMMAND</span>             <span class="hljs-constant">CREATED</span>             <span class="hljs-constant">STATUS</span>                     <span class="hljs-constant">PORTS</span>               <span class="hljs-constant">NAMES</span>
ac14ee1c187c        centos              <span class="hljs-string">"/bin/bash"</span>         <span class="hljs-number">18</span> seconds ago      <span class="hljs-constant">Exited</span> (<span class="hljs-number">0</span>) <span class="hljs-number">8</span> seconds ago                       berserk_curie       </code>

使用指定镜像 运行容器

<code>[root@ztydl ~]# docker  run -it --name vm1 centos bash
-<span class="ruby"><span class="hljs-symbol">d:</span> 后台运行容器,并返回容器<span class="hljs-constant">ID</span>;
</span>-<span class="ruby"><span class="hljs-symbol">i:</span> 以交互模式运行容器,通常与 -t 同时使用;
</span>-<span class="ruby"><span class="hljs-symbol">t:</span> 为容器重新分配一个伪输入终端,通常与 -i 同时使用;
</span>-<span class="ruby">-name=<span class="hljs-string">"nginx-lb"</span><span class="hljs-symbol">:</span> 为容器指定一个名称;</span></code>

将正在运行的已做修改的 容器 生成新的镜像

<code>[root<span class="hljs-variable">@ztydl</span> ~]<span class="hljs-comment"># docker commit -m "test asd" -a "ztyzty" 311ad zty-centos</span>
<span class="hljs-number">50</span>be09cb7fbc575053e73772f9af7fdbf89c65d993120462d8c56b73b0c3d7f4

[root<span class="hljs-variable">@ztydl</span> ~]<span class="hljs-comment"># docker images</span>
<span class="hljs-constant">REPOSITORY</span>                              <span class="hljs-constant">TAG</span>                 <span class="hljs-constant">IMAGE</span> <span class="hljs-constant">ID</span>            <span class="hljs-constant">CREATED</span>             <span class="hljs-constant">VIRTUAL</span> <span class="hljs-constant">SIZE</span>
zty-centos                              latest              <span class="hljs-number">50</span>be09cb7fbc        <span class="hljs-number">15</span> seconds ago      <span class="hljs-number">198.3</span> <span class="hljs-constant">MB</span></code>

将已有镜像保存为本地文件

<code>[root<span class="hljs-variable">@ztydl</span> ~]<span class="hljs-comment"># docker save -o zty-centos.tar.gz zty-centos</span>

[root<span class="hljs-variable">@ztydl</span> ~]<span class="hljs-comment"># docker load &lt; zty-centos.tar.gz</span></code>

使用本地模板 导入镜像

<code>[root<span class="hljs-variable">@ztydl</span> ~]<span class="hljs-comment"># cat zty-centos.tar.gz |docker import - import_os</span>
d83c7b9794a3e1ae88ff8093c4103fbbec34941f917ea1e890bf5b8c84e31729</code>

未经允许不得转载:冰点网络 » docker镜像管理命令学习

分享到:更多 ()

评论 抢沙发

评论前必须登录!