第 3 章 镜像 - 021 - Docker 镜像小结

镜像小结

镜像的常用操作子命令:

  • images    显示镜像列表
  • history   显示镜像构建历史
  • commit    从容器创建新镜像
  • build     从 Dockerfile 构建镜像
  • tag       给镜像打 tag
  • pull      从 registry 下载镜像
  • push      将 镜像 上传到 registry
  • rmi       删除 Docker host 中的镜像
  • search    搜索 Docker Hub 中的镜像

rmi

rmi 只能删除 host 上的镜像,不会删除 registry 的镜像。

如果一个镜像对应了多个 tag,只有当最后一个 tag 被删除时,镜像才被真正删除。例如 host 中 gsophy/aaa 镜像有两个 tag:

 root@ubuntu:~# docker images centos
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 1e1148e4cc2c weeks ago 202MB
centos v1 1e1148e4cc2c weeks ago 202MB
root@ubuntu:~#

删除其中 centos:v1 只是删除了 v1 tag,镜像本身没有删除。

 root@ubuntu:~# docker rmi centos:v1
Untagged: centos:v1
root@ubuntu:~#
root@ubuntu:~# docker images centos
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 1e1148e4cc2c weeks ago 202MB

只有当 centos:latest 也被删除时,整个镜像才会被删除。

 root@ubuntu:~# docker rmi centos:latest
Untagged: centos:latest
Untagged: centos@sha256:38777a4106f0072649128ea4236241345a3ed21c55abbbd53bad5342549f6126
Deleted: sha256:1e1148e4cc2c148c6890a18e3b2d2dde41a6745ceb4e5fe94a923d811bf82ddb
Deleted: sha256:071d8bd765171080d01682844524be57ac9883e53079b6ac66707e192ea25956
root@ubuntu:~# docker images centos
REPOSITORY TAG IMAGE ID CREATED SIZE
root@ubuntu:~#

search

search 让我们无需打开浏览器,在命令行中就可以搜索 Docker Hub 中的镜像。

 root@ubuntu:~# docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. [OK]
ansible/centos7-ansible Ansible on Centos7 [OK]
jdeathe/centos-ssh CentOS- 6.10 x86_64 / CentOS- 7.5. x86… [OK]
consol/centos-xfce-vnc Centos container with "headless" VNC session… [OK]
imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 [OK]
centos/mysql--centos7 MySQL 5.7 SQL database server
tutum/centos Simple CentOS docker image with SSH access
openshift/base-centos7 A Centos7 derived base image for Source-To-I…
gluster/gluster-centos Official GlusterFS Image [ CentOS- + Glust… [OK]
centos/postgresql--centos7 PostgreSQL is an advanced Object-Relational …
centos/python--centos7 Platform for building and running Python 3.5…
kinogmt/centos-ssh CentOS with SSH [OK]
openshift/jenkins--centos7 A Centos7 based Jenkins v2.x image for use w…
centos/php--centos7 Platform for building and running PHP 5.6 ap…
pivotaldata/centos-gpdb-dev CentOS image for GPDB development. Tag names…
openshift/wildfly--centos7 A Centos7 based WildFly v10. image for use …
openshift/jenkins--centos7 DEPRECATED: A Centos7 based Jenkins v1.x ima…
darksheer/centos Base Centos Image -- Updated hourly [OK]
pivotaldata/centos Base centos, freshened up a little with a Do…
pivotaldata/centos-mingw Using the mingw toolchain to cross-compile t…
pivotaldata/centos-gcc-toolchain CentOS with a toolchain, but unaffiliated wi…
blacklabelops/centos CentOS Base Image! Built and Updates Daily! [OK]
pivotaldata/centos7-test CentosOS image for GPDB testing
pivotaldata/centos7-build CentosOS image for GPDB compilation
smartentry/centos centos with smartentry [OK]
root@ubuntu:~#

想知道镜像都有哪些 tag,还是得访问 Docker Hub。

---------------------引用来自--------------------

https://mp.weixin.qq.com/s?__biz=MzIwMTM5MjUwMg==&mid=2653587632&idx=1&sn=75d558655ce7885ca531f950ca416b50&chksm=8d3080a9ba4709bfdcf507ff7be409ac23ec1f0fd6d8efdd893d7489d777b16a99f5b5d99304&scene=21#wechat_redirect

上一篇:Spring 框架简介


下一篇:java面试每日一题11