- 本文讲解 Docker 镜像操作的常用指令
- docker Hub 官网:https://hub.docker.com/
镜像操作
检索云端镜像
-使用 指令 docker search 关键字 可以检索 (搜索) Docker Hub 官网上提供的所有镜像,之后我们就可以下载需要的镜像
-检索 " mysql ":[root@localhost ~]# docker search mysql
-检索 " redis ":[root@localhost ~]# docker search redis
[root@localhost ~]# docker search mysql INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/mysql MySQL is a widely used, open-source relati... 6728 [OK] docker.io docker.io/mariadb MariaDB is a community-developed fork of M... 2141 [OK] docker.io docker.io/mysql/mysql-server Optimized MySQL Server Docker images. Crea... 495 [OK] docker.io docker.io/percona Percona Server is a fork of the MySQL rela... 360 [OK] docker.io docker.io/zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 114 [OK] docker.io docker.io/hypriot/rpi-mysql RPi-compatible Docker Image with Mysql 93 docker.io docker.io/zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server ... 62 [OK] docker.io docker.io/centurylink/mysql Image containing mysql. Optimized to be li... 60 [OK] docker.io docker.io/1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 43 [OK] docker.io docker.io/centos/mysql-57-centos7 MySQL 5.7 SQL database server 35 docker.io docker.io/mysql/mysql-cluster Experimental MySQL Cluster Docker images. ... 33 docker.io docker.io/tutum/mysql Base docker image to run a MySQL database ... 32 docker.io docker.io/schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic back... 20 [OK] docker.io docker.io/bitnami/mysql Bitnami MySQL Docker Image 16 [OK] docker.io docker.io/zabbix/zabbix-proxy-mysql Zabbix proxy with MySQL database support 15 [OK] docker.io docker.io/linuxserver/mysql A Mysql container, brought to you by Linux... 14 docker.io docker.io/centos/mysql-56-centos7 MySQL 5.6 SQL database server 9 docker.io docker.io/circleci/mysql MySQL is a widely used, open-source relati... 6 docker.io docker.io/openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 ima... 6 docker.io docker.io/dsteinkopf/backup-all-mysql backup all DBs in a mysql server 4 [OK] docker.io docker.io/mysql/mysql-router MySQL Router provides transparent routing ... 2 docker.io docker.io/openzipkin/zipkin-mysql Mirror of https://quay.io/repository/openz... 1 docker.io docker.io/ansibleplaybookbundle/mysql-apb An APB which deploys RHSCL MySQL 0 [OK] docker.io docker.io/cloudfoundry/cf-mysql-ci Image used in CI of cf-mysql-release 0 docker.io docker.io/cloudposse/mysql Improved `mysql` service with support for ... 0 [OK] [root@localhost ~]#
INDEX:索引
NAME:镜像名称
DESCRIPTION:描述
STARS:关注人数,单位为 k
OFFICIAL:是否为官方发布),[ok] 则表示此版本为官方发行版本
AUTOMATED:是否自动配置,[ok] 则表示镜像已经自动配置好了,获取就能直接使用,否则需要自己手动配置
- 如上所示所有的搜索结果其实都是从 Docker Hub 上获取来的,所以我们自己也可以官网上直接查找
下载镜像
- 使用命令:docker pull 镜像名:tag,可以从 Docker Hub 下载指定的镜像,“ :tag ” 不写时默认下载最新版本的镜像,也可以自己指定 tag 从而下载指定版本的镜像,tag 名称可以从 Docker Hub 上自己查看
[root@localhost ~]# docker search mysql INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/mysql MySQL is a widely used, open-source relati... 6728 [OK] docker.io docker.io/mariadb MariaDB is a community-developed fork of M... 2141 [OK] docker.io docker.io/mysql/mysql-server Optimized MySQL Server Docker images. Crea... 495 [OK] .......
- 下载上面 NAME 为 docker.io/msql 镜像为例,使用 " docker pull mysql "即可下载, 前面的 " docker.io/" 可写可不写
- 如下所示没有提供 "tag" 时, “Using default tag: latest” 表示默认使用 "latest" 版本
- 下载成功之后,可以使用 " docker images " 查看本地下载好的所有镜像
[root@localhost ~]# docker pull mysql Using default tag: latest Trying to pull repository docker.io/library/mysql ... latest: Pulling from docker.io/library/mysql be8881be8156: Pull complete c3995dabd1d7: Pull complete 9931fdda3586: Pull complete bb1b6b6eff6a: Pull complete a65f125fa718: Pull complete 2d9f8dd09be2: Pull complete 37b912cb2afe: Pull complete 54242fcd8eaa: Pull complete 0a9d4d211511: Pull complete 270ae5bd02c2: Pull complete 9b55b8e72e70: Pull complete 68083f7985cd: Pull complete Digest: sha256:d39a8ab7679df309e7eff6ddba434ad5747cc2a2acee2d7c60d8221c9acedcad Status: Downloaded newer image for docker.io/mysql:latest [root@localhost ~]#
如下所示下载的是 docker.io/mysql 5.7 版本的镜像
[root@localhost ~]# docker pull mysql:5.7 Trying to pull repository docker.io/library/mysql ... 5.7: Pulling from docker.io/library/mysql be8881be8156: Already exists c3995dabd1d7: Already exists 9931fdda3586: Already exists bb1b6b6eff6a: Already exists a65f125fa718: Already exists 2d9f8dd09be2: Already exists 37b912cb2afe: Already exists faf9da46e0cf: Pull complete ffcedc9e8600: Pull complete 6e11f2447e86: Pull complete 02243b284270: Pull complete Digest: sha256:e25e2768e910223db3095c1560aa2255371986b24fbebf4b015bae3cc60b9b34 Status: Downloaded newer image for docker.io/mysql:5.7 [root@localhost ~]#
查看本地镜像
使用命令 docker images 查看本地下载好的所有镜像
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/mysql 5.7 43b029b6b640 22 hours ago 372 MB docker.io/mysql latest 29e0ae3b69b9 22 hours ago 484 MB [root@localhost ~]#
REPOSITORY :仓库,即下载的镜像名称
TAG:标识,通常为版本号
IMAGE ID:镜像id,删除时根据镜像id进行删除
CRREATED:镜像创建时间
SIZE:镜像大小
删除镜像
使用 docker rmi image-id 命令删除指定的本地镜像
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/mysql 5.7 43b029b6b640 22 hours ago 372 MB docker.io/mysql latest 29e0ae3b69b9 22 hours ago 484 MB [root@localhost ~]# docker rmi 43b029b6b640 Untagged: docker.io/mysql:5.7 Untagged: docker.io/mysql@sha256:e25e2768e910223db3095c1560aa2255371986b24fbebf4b015bae3cc60b9b34 Deleted: sha256:43b029b6b6406b40f1ba51b069980b5c14b701786830a41ebb489ad3bbf3d928 Deleted: sha256:e8793f33a59faabf48ec2b41dff592700651385fc2d0e4ddc2f7a6efbd0c03c3 Deleted: sha256:06f716d6d745ca2ab39f21f40ba757cbbd93b6189ca47030f4888442b9c2f9ca Deleted: sha256:0c7d7ee852d955b7ec7353dc367b26ee59c029243e631fc31a53847bffe1852b Deleted: sha256:35c70a35928fd6ce30c1495b9782b53b69fe0d023c35ad047072e4d7d388a753 [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/mysql latest 29e0ae3b69b9 22 hours ago 484 MB [root@localhost ~]# docker rmi 29e0ae3b69b9 Untagged: docker.io/mysql:latest Untagged: docker.io/mysql@sha256:d39a8ab7679df309e7eff6ddba434ad5747cc2a2acee2d7c60d8221c9acedcad Deleted: sha256:29e0ae3b69b9031ab7d7fd3024057b9441d74c8244e583cfb48697109148ca71 Deleted: sha256:e510a8f0a60462d0280381e93018635f8986c308550dabce0be5249c3402c338 Deleted: sha256:7360cba3164f094ead4b968263cabeed376e7306ca6415c824d63ff7d2c22203 Deleted: sha256:e26ff419bf2626b93431acf08fc734cb88eed5dea413bd05965ba1c51dc9c671 Deleted: sha256:5b9acfeae5767ffb16ef495d68de01b750ac5efcf2af474d695b1fead7c2dabc Deleted: sha256:3f55b1f8de59e6ba35f38376b4a7ee48ffbb32f23500d16400a18c6d59ad1803 Deleted: sha256:d8a947a6bf007b7b3f857fd157092aa938cc01780175eda5c300847f2758ba6f Deleted: sha256:424c40c7a715a28330453b0ec3b5afc97caa851a56d365c65a97b583b733b81b Deleted: sha256:202db300227b8c870b421aa0a0a11b44cb916401ef3a34bcc2a5efcb30a3ea78 Deleted: sha256:20f3dff2c1b6f8409b53e4e203132f7ebb2dfd7dc612d87e4a93302a5a8f5c1a Deleted: sha256:3131a4917b53634699929d8ff7e2b2bd9469f3f5ab08daf41d1c6b90e0f18b44 Deleted: sha256:9996a15396359708cb2177cfdbe8fcb9f65124142edb9b1d3550f3eb87360676 Deleted: sha256:cdb3f9544e4c61d45da1ea44f7d92386639a052c620d1550376f22f5b46981af [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE [root@localhost ~]#