跳到主要内容

十七、Docker 查找镜像

在上一章节的末尾,因为本地不存在 latest 标签的 ubuntu,所以 Docker 就跑到远程去拉取 ubuntu:latest 镜像了

docker pull 拉取镜像

当我们在本地主机上使用一个不存在的镜像时 Docker 就会自动下载这个镜像

如果我们想预先下载这个镜像,我们可以使用 docker pull 命令来下载它

例如下面的命令,从远程预先拉取 ubuntu:16.10 到本地

[root@pottercoding.cn ~]# docker pull ubuntu:16.10
16、10: Pulling from library/ubuntu
dca7be20e546: Pull complete
40bca54f5968: Pull complete
61464f23390e: Pull complete
d99f0bcd5dc8: Pull complete
120db6f90955: Pull complete
Digest: sha256:8dc9652808dc091400d7d5983949043a9f9c7132b15c14814275d25f94bca18a
Status: Downloaded newer image for ubuntu:16.10

下载完成后,我们可以直接使用这个镜像来运行容器

[root@pottercoding.cn ~]# docker run -it ubuntu:16.10 /bin/bash

查找镜像

如果本地没有想要的镜像,那么我们可以从远程仓库上查找

从远程仓库上查找镜像有两种方法

1、 是通过访问DockerHub网站来搜索镜像;

Docker Hub 网址为 [https://hub.docker.com/][https_hub.docker.com]

2、 是通过dockersearch命令来查找镜像;

两种方法都好用,一般情况下对于精确的镜像,我们都使用 docker search 命令,比如 nginxphppython 等,除此之外,我们使用 Docker Hub 网站来查找

下面,我们就使用 docker search 命令来查找 nginx 的镜像