docker_practice/image/pull.md

39 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

## 获取镜像
可以使用`docker pull`命令来从仓库获取所需要的镜像。
下面的例子将从Docker Hub仓库下载一个Ubuntu 12.04操作系统的镜像。
```
$ sudo docker pull ubuntu:12.04
Pulling repository ubuntu
ab8e2728644c: Pulling dependent layers
511136ea3c5a: Download complete
5f0ffaa9455e: Download complete
a300658979be: Download complete
904483ae0c30: Download complete
ffdaafd1ca50: Download complete
d047ae21eeaf: Download complete
```
下载过程中,会输出获取镜像的每一层信息。
该命令实际上相当于`$ sudo docker pull registry.hub.docker.com/ubuntu:12.04`命令,即从注册服务器`registry.hub.docker.com`中的`ubuntu`仓库来下载标记为`12.04`的镜像。
有时候官方仓库注册服务器下载较慢,可以从其他仓库下载。
从其它仓库下载时需要指定完整的仓库注册服务器地址。例如
```
$ sudo docker pull www.dockerpool.com:5000/ubuntu:12.04
Pulling www.dockerpool.com:5000/ubuntu
ab8e2728644c: Pulling dependent layers
511136ea3c5a: Download complete
5f0ffaa9455e: Download complete
a300658979be: Download complete
904483ae0c30: Download complete
ffdaafd1ca50: Download complete
d047ae21eeaf: Download complete
```
完成后即可随时使用该镜像了例如创建一个容器让其中运行bash应用。
```
$ sudo docker run -t -i ubuntu:12.04 /bin/bash
root@fe7fc4bd8fc9:/#
```