一 列出镜像列表
使用docker images来列出本地主机上的镜像。
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/ubuntu latest 0ef2e08ed3fa 2 weeks ago 130 MB
docker.io/hello-world latest 48b5124b2768 9 weeks ago 1.84 kB
docker.io/ubuntu 15.10 9b9cb95443b5 7 months ago 137.2 MB
各个选项说明:
REPOSTITORY:表示镜像的仓库源。
TAG:镜像的标签。
IMAGE ID:镜像ID。
CREATED:镜像创建时间。
SIZE:镜像大小。
同一仓库源可以有多个TAG,代表这个仓库源的不同个版本,如ubuntu仓库源里,有15.10、latest等多个不同的版本,我们使用REPOSTITORY:TAG来定义不同的镜像。
所以,我们如果要使用版本为15.10的ubuntu系统镜像来运行容器时,命令如下:
[root@localhost ~]# docker run -t -i ubuntu:15.10 /bin/bash
root@e26a0172a0aa:/#
如果要使用版本为latest的ubuntu系统镜像来运行容器时,命令如下:
[root@localhost ~]# docker run -t -i ubuntu:latest /bin/bash
root@bf67651b183f:/#
如果不指定一个镜像的版本标签,例如只使用 ubuntu,docker 将默认使用 ubuntu:latest 镜像。
二 获取一个新的镜像
当在本地主机上使用一个不存在的镜像时,Docker就会自动下载这个镜像。如果想预先下载这个镜像,可以使用docker pull命令来下载它。
[root@localhost ~]# docker pull ubuntu
Using default tag: latest
Trying to pull repository docker.io/library/ubuntu ...
latest: Pulling from docker.io/library/ubuntu
d54efb8db41d: Pull complete
f8b845f45a87: Pull complete