Docker 运行前需要本地存在对应的镜像,如果本地不存在该镜像,那么会自动从镜像仓库(Docker Hub)下载镜像。


Docker 获取镜像

DockerHub上存在许多优质的镜像,一般使用docker pull从仓库拉取(和Git拉取远程仓库一样),命令格式如下;


docker pull  [option] [docker registry地址[:端口号]]/仓库名:标签

具体可以使用docker pull --help 查看:

root@iZwz99z2ljzabken0hvkjrZ:~# 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)
  -q, --quiet                   Suppress verbose output

因为设置了docker 仓库的地址(默认是DockerHub),那么一般操作的时候可以不用填写注册中心地址和端口号,当时如果是操作其他注册中心(比如阿里云),那么docker pull的命令可能如下:

docker pull registry.cn-shanghai.aliyuncs.com/dimple-hub/dimpleblog:least


比如这里下载tomcat

docker pull tomcat:7

PS:如果下载速度较慢,可以参照Docker配置镜像加速器 Docker学习(七)


还有一个不常用的命令

docker search tomcat

这样就可以搜索,但是很鸡肋。一般推荐直接去Docker Hub上看,因为这个搜索出来的不显示tag。如下:


root@iZwz99z2ljzabken0hvkjrZ:~# docker search tomcat
NAME                          DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
tomcat                        Apache Tomcat is an open source implementati…   2492                [OK]                
tomee                         Apache TomEE is an all-Apache Java EE certif…   66                  [OK]                
dordoka/tomcat                Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base…   53                                      [OK]
bitnami/tomcat                Bitnami Tomcat Docker Image                     29                                      [OK]
kubeguide/tomcat-app          Tomcat image for Chapter 1                      26                                      
consol/tomcat-7.0             Tomcat 7.0.57, 8080, "admin/admin"              16                                      [OK]
cloudesire/tomcat             Tomcat server, 6/7/8                            15                                      [OK]
aallam/tomcat-mysql           Debian, Oracle JDK, Tomcat & MySQL              11                                      [OK]
tutum/tomcat                  Base docker image to run a Tomcat applicatio…   11                                      
arm32v7/tomcat                Apache Tomcat is an open source implementati…   8                                       
rightctrl/tomcat              CentOS , Oracle Java, tomcat application ssl…   5                                       [OK]
maluuba/tomcat7-java8         Tomcat7 with java8.                             3                                       
arm64v8/tomcat                Apache Tomcat is an open source implementati…   2                                       
amd64/tomcat                  Apache Tomcat is an open source implementati…   2                                       
ppc64le/tomcat                Apache Tomcat is an open source implementati…   1                                       
camptocamp/tomcat-logback     Docker image for tomcat with logback integra…   1                                       [OK]
99taxis/tomcat7               Tomcat7                                         1                                       [OK]
i386/tomcat                   Apache Tomcat is an open source implementati…   1                                       
secoresearch/tomcat-varnish   Tomcat and Varnish 5.0                          0                                       [OK]
s390x/tomcat                  Apache Tomcat is an open source implementati…   0                                       
cfje/tomcat-resource          Tomcat Concourse Resource                       0                                       
oobsri/tomcat8                Testing CI Jobs with different names.           0                                       
jelastic/tomcat               An image of the Tomcat Java application serv…   0                                       
appsvc/tomcat                                                                 0                                       
picoded/tomcat7               tomcat7 with jre8 and MANAGER_USER / MANAGER…   0                                       [OK]