镜像的管理命令
镜像、容器、仓库之间的关系
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/是否自动流程构建 |
---|---|---|---|---|
NAME | DESCRIPTION | STARS | OFFICIAL | AUTOMATED |
mysql | MySQL is a widely used, open-source relation… | 9152 | [OK] | |
mariadb | MariaDB is a community-developed fork of MyS… | 3248 | [OK] | |
mysql/mysql-server | Optimized 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