02、docker镜像的管理命令

镜像的管理命令

镜像、容器、仓库之间的关系

在这里插入图片描述

1、docker search 搜索镜像

[root@localhost ~]# docker search --help 

Usage:  docker search [OPTIONS] TERM

Search the Docker Hub for images

Options:
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print search using a Go template
      --limit int       Max number of search results (default 25)
      --no-trunc        Don't truncate output
[root@localhost ~]# 

–filter 是通过点赞数过滤

搜索远程仓库镜像,以mysql为例:

[root@localhost ~]# docker search mysql
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   11213     [OK]       
mariadb                           MariaDB Server is a high performing open sou…   4261      [OK]       
mysql/mysql-server                Optimized MySQL Server Docker images. Create…   833                  [OK]
centos/mysql-57-centos7           MySQL 5.7 SQL database server                   91                   
mysql/mysql-cluster               Experimental MySQL Cluster Docker images. Cr…   88                   
centurylink/mysql                 Image containing mysql. Optimized to be link…   59                   [OK]
databack/mysql-backup             Back up mysql databases to... anywhere!         45                   
deitch/mysql-backup               REPLACED! Please use http://hub.docker.com/r…   41                   [OK]
prom/mysqld-exporter                                                              40                   [OK]
tutum/mysql                       Base docker image to run a MySQL database se…   35                   
linuxserver/mysql                 A Mysql container, brought to you by LinuxSe…   30                   
schickling/mysql-backup-s3        Backup MySQL to S3 (supports periodic backup…   30                   [OK]
mysql/mysql-router                MySQL Router provides transparent routing be…   21                   
centos/mysql-56-centos7           MySQL 5.6 SQL database server                   20                   
arey/mysql-client                 Run a MySQL client from a docker container      18                   [OK]
fradelg/mysql-cron-backup         MySQL/MariaDB database backup using cron tas…   16                   [OK]
openshift/mysql-55-centos7        DEPRECATED: A Centos7 based MySQL v5.5 image…   6                    
cytopia/mysql-5.5                 MySQL 5.5 on CentOS 7                           4                    [OK]
devilbox/mysql                    Retagged MySQL, MariaDB and PerconaDB offici…   3                    
ansibleplaybookbundle/mysql-apb   An APB which deploys RHSCL MySQL                2                    [OK]
jelastic/mysql                    An image of the MySQL database server mainta…   2                    
centos/mysql-80-centos7           MySQL 8.0 SQL database server                   1                    
widdpim/mysql-client              Dockerized MySQL Client (5.7) including Curl…   1                    [OK]
vitess/mysqlctld                  vitess/mysqlctld                                1                    [OK]
monasca/mysql-init                A minimal decoupled init container for mysql    0                    
[root@localhost ~]#

[root@localhost ~]# docker search mysql --filter=STARS=3000
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql     MySQL is a widely used, open-source relation…   11213     [OK]       
mariadb   MariaDB Server is a high performing open sou…   4261      [OK]   

结果类似下面的表格,但是终端窗口小的话,会换行。
换行之后看起来真是痛苦。你可以把字调小一点。

NAME/名称DESCRIPTION/描述STARS/点赞数OFFICIAL/是否官方AUTOMATED/是否自动流程构建
NAMEDESCRIPTIONSTARSOFFICIALAUTOMATED
mysqlMySQL is a widely used, open-source relation…9152[OK]
mariadbMariaDB is a community-developed fork of MyS…3248[OK]
mysql/mysql-serverOptimized MySQL Server Docker images. Create…676[OK]

在这里插入图片描述
除了上面的方法搜索镜像之外,你还可以访问官网:hub.docker.com

2、docker pull 下载镜像

[root@localhost ~]# docker pull --help 

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

Pull an image or a repository from a registry

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
[root@localhost ~]# 

以下载MySQL为例。不用加任何版本号,默认就是最新版latest版本

[root@localhost ~]# docker pull mysql
Using default tag: latest      #如果不写tag,默认下载最新版本latest
latest: Pulling from library/mysql
33847f680f63: Pull complete    #分层下载,docker的核心:联合文件系统
5cb67864e624: Pull complete 
1a2b594783f5: Pull complete 
b30e406dd925: Pull complete 
48901e306e4c: Pull complete 
603d2b7147fd: Pull complete 
802aa684c1c4: Pull complete 
715d3c143a06: Pull complete 
6978e1b7a511: Pull complete 
f0d78b0ac1be: Pull complete 
35a94d251ed1: Pull complete 
36f75719b1a9: Pull complete 
Digest: sha256:8b928a5117cf5c2238c7a09cd28c2e801ac98f91c3f8203a8938ae51f14700fd   #签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest    #真实地址


#####下载mysql5.7指定版本的镜像

[root@localhost ~]# docker pull mysql:5.7
5.7: Pulling from library/mysql
33847f680f63: Already exists   #上面下载最新版的时候已经下载了,这里就共用
5cb67864e624: Already exists 
1a2b594783f5: Already exists 
b30e406dd925: Already exists 
48901e306e4c: Already exists 
603d2b7147fd: Already exists 
802aa684c1c4: Already exists 
5b5a19178915: Pull complete 
f9ce7411c6e4: Pull complete 
f51f6977d9b2: Pull complete 
aeb6b16ce012: Pull complete 
Digest: sha256:be70d18aedc37927293e7947c8de41ae6490ecd4c79df1db40d1b5b5af7d9596
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
[root@localhost ~]# 

下载mysql5.7的镜像

3、docker images 查看本地镜像

先看下不加参数的效果

[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
mysql         5.7       8cf625070931   13 days ago    448MB
mysql         latest    c60d96bd2b77   13 days ago    514MB
hello-world   latest    d1165f221234   5 months ago   13.3kB
  • REPOSITORY:名字
  • TAG:版本
  • IMAGE ID:镜像ID
  • CREATED:创建时间
  • SIZE:大小

命令帮助

[root@localhost ~]# docker images --help 

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

List 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   Pretty-print images using a Go template
      --no-trunc        Don't truncate output
  -q, --quiet           Only show image IDs

  • a 显示所有镜像,包括没启动的
  • q 仅显示镜像的ID
[root@localhost ~]# docker images -a
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   5 months ago   13.3kB
[root@localhost ~]# docker images -q
d1165f221234
[root@localhost ~]# 

举例:

docker images  或者 docker image ls
docker images -q   #查询本地镜像的所有ID号

4、docker image rmi 镜像删除

[root@localhost ~]# docker rmi --help 
Usage:  docker rmi [OPTIONS] IMAGE [IMAGE...]
Remove one or more images
Options:
  -f, --force      #强制删除镜像
      --no-prune   #不要删除未标记的父项

举例:

强制删除镜像

docker rmi -f 8cf625070931

删除所有镜像

docker rmi -f $(docker images -aq)   #生产环境绝对不能使用此命令,除非你想清空镜像

5、docker image save 导出镜像

命令格式:

docker image save 参数 保存的文件名 镜像名和版本号

例如:我们导出MySQL5.5这个镜像到当前目录

docker image save -o docker_mysql5.5.tar.gz mysql:5.5

6、docker image load 导入镜像

例如:从当前目录导入docker_mysql5.5.tar.gz

docker image load -i  docker_mysql5.5.tar.gz
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

亦良Cool

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

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

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

打赏作者

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

抵扣说明:

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

余额充值