Docker镜像相关命令

Docker 提供了多个用于管理镜像的命令,包括拉取、构建、查看、标记、删除等。以下是这些命令的详细解释和使用方法:


一、docker pull :拉取镜像

从远程仓库(如 Docker Hub、私有仓库等)拉取镜像到本地。

命令:docker pull <镜像名>:<标签>

帮助:

[root@Centos7-T1 ~]#docker pull --help
Usage:  docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Download an image from a registry
Aliases:
  docker image pull, docker pull

Options:
  -a, --all-tags                Download all tagged images in the repository
      --disable-content-trust   Skip image verification (default true)
      --platform string         Set platform if server is multi-platform capable
  -q, --quiet                   Suppress verbose output


-a, --all-tags            #一般用户自己的镜像仓库,拉取所有的镜像。
--disable-content-trust   #跳过镜像的验证,默认是true(第三方可以验证)
--platform string         #支持多平台,指定平台(不常用)
-q, --quiet               #抑制冗长输出

1、基本用法

[root@Centos7-T1 ~]#docker pull zookeeper:3.7.1

2、不加tag,默认为latest版本。

[root@Centos7-T1 ~]#docker pull tomcat

3、抑制冗长输出

#-q  抑制冗长输出,简化输出
[root@Centos7-T1 ~]#docker pull -q ubuntu
docker.io/library/ubuntu:latest
[root@Centos7-T1 ~]#docker images
REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
ubuntu                latest    ba6acccedd29   18 months ago   72.8MB

4、通过 digest 拉取

DIGEST:镜像内容哈希值,内容散列。 SHA256,一种哈希算法

有些时候不方便使用name:tag,就可以使用digest /daɪˈdʒest/

在这里插入图片描述

#使用哈希值拉取
[root@Centos7-T1 ~]#docker pull tomcat@sha256:cb3e139e91a045529d46a80cd97cae9dd2be37609a167bdb5febb6673451ae91
docker.io/library/tomcat@sha256:cb3e139e91a045529d46a80cd97cae9dd2be37609a167bdb5febb6673451ae91: Pulling from library/tomcat
1bc677758ad7: Pull complete 
0d0e0ecb256a: Pull complete 
c24bf4c725c2: Pull complete 
4fb255c76461: Pull complete 
b388fec4cd21: Pull complete 
4800bac131aa: Pull complete 
fc4cc5ff9156: Pull complete 
Digest: sha256:cb3e139e91a045529d46a80cd97cae9dd2be37609a167bdb5febb6673451ae91
Status: Downloaded newer image for tomcat@sha256:cb3e139e91a045529d46a80cd97cae9dd2be37609a167bdb5febb6673451ae91
docker.io/library/tomcat@sha256:cb3e139e91a045529d46a80cd97cae9dd2be37609a167bdb5febb6673451ae91
[root@Centos7-T1 ~]#docker images
REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
tomcat                <none>    311570738ca3   39 hours ago    475MB


二、docker images:查看镜像

通过docker images 命令可查看本地所有镜像资源信息。这些镜像会按照镜像被创建的时间由近及远排序。

命令:docker images [选项]

帮助

[root@Centos7-T1 ~]#docker images --help
Usage:  docker images [OPTIONS] [REPOSITORY[:TAG]]
List images
Aliases:
  docker image ls, docker image list, docker images
Options:
  -a, --all             Show all images (default hides intermediate images)
      --digests         Show digests
  -f, --filter filter   Filter output based on conditions provided
      --format string   Format output using a custom template:
                        'table':            Print output in table format with column
                        headers (default)
                        'table TEMPLATE':   Print output in table format using the
                        given Go template
                        'json':             Print in JSON format
                        'TEMPLATE':         Print output using the given Go template.
                        Refer to https://docs.docker.com/go/formatting/ for more
                        information about formatting output with templates
      --no-trunc        Don't truncate output
  -q, --quiet           Only show image IDs


 -a, --all     #显示所有
 --digests     #显示digests
 --no-trunc    #不截取,没有删减
 -q, --quiet   #只显示镜像id
 -f, --filter  #过滤

1、基础用法

[root@Centos7-T1 ~]#docker images
REPOSITORY            TAG       IMAGE ID       CREATED         SIZE
tomcat                <none>    311570738ca3   39 hours ago    475MB
zookeeper             3.7       36c607e7b14d   16 months ago   278MB
tomcat                latest    fb5657adc892   16 months ago   680MB
redis                 latest    7614ae9453d1   16 months ago   113MB
mysql                 5.7       c20987f18b13   16 months ago   448MB
centos                latest    5d0da3dc9764   19 months ago   231MB
portainer/portainer   latest    580c0e4e98b0   2 years ago     79.1MB

# REPOSITORY :镜像仓库名称
# TAG :镜像版本号
# IMAGE ID :镜像的唯一标识
# CREATE :镜像的创建时间
# SIZE :镜像大小

2、查看指定镜像

[root@Centos7-T1 ~]#docker images tomcat
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
tomcat       <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Cyan_Jiang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值