Docker(2)- docker images、info、search、pull命令详解

92 阅读4分钟

携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第23天,点击查看活动详情

docker images作用

列出所有的本地镜像

 

语法格式

docker images [OPTIONS] [REPOSITORY[:TAG]]

 

options 说明

options作用
-a, --all列出本地所有的镜像(含中间镜像层,默认情况下,过滤掉中间映像层)
--digests显示镜像的摘要信息
-f, --filter filter显示满足条件(filter)的镜像
--format string 使用模板格式化输出
--no-trunc显示完整的镜像信息
-q, --quiet 只显示镜像ID

 

实际栗子

点击放大即可看清楚

 

列表含义

[root@iz2zeak7sgj6i7hrb2g862z ~] docker images
REPOSITORY            TAG                 IMAGE ID            CREATED           SIZE
hello-world           latest              bf756fb1ae65        4 months ago     13.3kB
mysql                 5.7                 b84d68d0a7db        6 days ago       448MB

# 解释
#REPOSITORY            # 镜像的仓库源
#TAG                # 镜像的标签(版本)        ---lastest 表示最新版本
#IMAGE ID            # 镜像的id
#CREATED            # 镜像的创建时间
#SIZE                # 镜像的大小

docker info 作用

显示 Docker 系统信息,包括镜像和容器数

 

语法格式

docker info [OPTIONS]

 

options 说明

-f:使用给定的模板格式化输出(一般不用)

 

实际栗子

  • Client:docker 客户端信息
  • Server:docker 服务端信息
  • Containers:容器数量
  • Images:镜像数量
  • Server Version:docker 版本
  • Docker Root Dir:docker 根目录
  • Registry Mirrors:当前使用的镜像源

docker search作用

从 Docker Hub 查找镜像

 

语法格式

docker search [OPTIONS] TERM

 

options 说明

option作用
-f, --filter filter根据提供的 filter 过滤输出
--limit int搜索结果条数最大为 int(默认25)
--no-trunc显示完整的镜像 description
--format使用 Go 模板进行美观打印

 

简单栗子

 

--filter 栗子

stars 的栗子

搜索 star 数量>3 的 busybox 镜像并打印详细描述

docker search --filter=stars=3 --no-trunc busybox                                                                     
NAME                    DESCRIPTION                                                                               STARS     OFFICIAL   AUTOMATED
busybox                 Busybox base image.                                                                       2272      [OK]
progrium/busybox                                                                                                  70                   [OK]
radial/busyboxplus      Full-chain, Internet enabled, busybox made from scratch. Comes in git and cURL flavors.   40                   [OK]
yauritux/busybox-curl   Busybox with CURL                                                                         16
arm32v7/busybox         Busybox base image.                                                                       9
armhf/busybox           Busybox base image.                                                                       6
odise/busybox-curl                                                                                                4                    [OK]
arm64v8/busybox         Busybox base image.

 

搜索 star 数量>3000 的 mysql 镜像

docker search mysql --filter=STARS=3000                                                                          
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql     MySQL is a widely used, open-source relation…   11063     [OK]
mariadb   MariaDB Server is a high performing open sou…   4193      [OK]

 

is-automated 的栗子

搜索自动构建的 busybox 镜像

docker search --filter is-automated=true busybox                                                                     
NAME                     DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
progrium/busybox                                                         70                   [OK]
radial/busyboxplus       Full-chain, Internet enabled, busybox made f…   40                   [OK]
odise/busybox-curl                                                       4                    [OK]
odise/busybox-python                                                     4                    [OK]
prom/busybox             Prometheus Busybox Docker base images           2                    [OK]
ggtools/busybox-ubuntu   Busybox ubuntu version with extra goodies       0                    [OK]

能看到 AUTOMATED 都是 OK

 

is-official 的栗子

搜索 star 数量>3 且是官方版本的 busybox 镜像

docker search --filter is-official=true --filter stars=3 busybox                                                  
NAME      DESCRIPTION           STARS     OFFICIAL   AUTOMATED
busybox   Busybox base image.   2272      [OK]

能看到 OFFICIAL 是 OK

docker pull作用

从镜像仓库中拉取或更新镜像

 

语法格式

docker pull [OPTIONS] NAME[:TAG|@DIGEST]

TAG:标签,不写的话默认是 latest 最新版 

 

看看 docker-hub 上的 Tag

 

options 说明

option作用
-a, --all-tags拉取所有 tagged 镜像
--disable-content-trust 忽略镜像的校验,默认开启
-q, --quiet概要输出
--platform string若服务支持多平台,这里可以设置平台

 

实际栗子

从 Docker Hub下载java最新版镜像

docker pull java 

 

从 Docker Hub下载 REPOSITORY 为 java 的所有镜像

docker pull -a java

 

下载镜像的过程

[root@iz2zeak7sgj6i7hrb2g862z ~]# docker pull tomcat:8
8: Pulling from library/tomcat #如果不写tag,默认就是latest
90fe46dd8199: Already exists   #分层下载: docker image 的核心 联合文件系统
35a4f1977689: Already exists   # Alrea exists 表示本地已存在对应的文件,不需要重复下载,提高速度,减少内存占用率
bbc37f14aded: Already exists 
74e27dc593d4: Already exists 
93a01fbfad7f: Already exists 
1478df405869: Pull complete    # 本地没有对应的文件,需要下载,后面再用到该文件的时候就不用再下载了
64f0dd11682b: Pull complete 
68ff4e050d11: Pull complete 
f576086003cf: Pull complete 
3b72593ce10e: Pull complete 
Digest: sha256:0c6234e7ec9d10ab32c06423ab829b32e3183ba5bf2620ee66de866df # 签名防伪
Status: Downloaded newer image for tomcat:8
docker.io/library/tomcat:8 # 真实地址

 

等价写法

docker pull tomcat:8
docker pull docker.io/library/tomcat:8