Docker 主機安裝之后,本地并沒有鏡像。
docker image pull 是下載鏡像的命令。鏡像從遠程鏡像倉庫服務的倉庫中下載。
默認情況下,鏡像會從 Docker Hub 的倉庫中拉取。docker image pull alpine:latest 命令會從 Docker Hub 的 alpine 倉庫中拉取標簽為 latest 的鏡像。
Linux Docker主機本地鏡像倉庫通常位于/var/lib/docker/,Windows Docker主機則是C:\ProgramData\docker\windowsfilter。
可以使用以下命令檢查 Docker 主機的本地倉庫中是否包含鏡像。
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
將鏡像取到 Docker 主機本地的操作是拉取。所以,如果讀者想在 Docker 主機使用最新的 Ubuntu 鏡像,需要拉取它。通過下面的命令可以將鏡像拉取到本地,并觀察其大小。
提示:如果使用 Linux,并且還沒有將當前用戶加入到本地 Docker UNIX 組中,則需要在下面的命令前面添加 sudo。
Windows示例如下。
> docker image pull microsoft/powershell:nanoserver
nanoserver: Pulling from microsoft/powershell
bce2fbc256ea: Pull complete
58f68fa0ceda: Pull complete
04083aac0446: Pull complete
e42e2e34b3c8: Pull complete
0c10d79c24d4: Pull complete
715cb214dca4: Pull complete
a4837c9c9af3: Pull complete
2c79a32d92ed: Pull complete
11a9edd5694f: Pull complete
d223b37dbed9: Pull complete
aee0b4393afb: Pull complete
0288d4577536: Pull complete
8055826c4f25: Pull complete
Digest: sha256:090fe875...fdd9a8779592ea50c9d4524842
Status: Downloaded newer image for microsoft/powershell:nanoserver
>
> docker image pull microsoft/dotnet:latest
latest: Pulling from microsoft/dotnet
bce2fbc256ea: Already exists
4a8c367fd46d: Pull complete
9f49060f1112: Pull complete
0334ad7e5880: Pull complete
ea8546db77c6: Pull complete
710880d5cbd5: Pull complete
d665d26d9a25: Pull complete
caa8d44fb0b1: Pull complete
cfd178ff221e: Pull complete
Digest: sha256:530343cd483dc3e1...6f0378e24310bd67d2a
Status: Downloaded newer image for microsoft/dotnet:latest
>
> docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
microsoft/dotnet latest 831..686d 7 hrs ago 1.65 GB
microsoft/powershell nanoserver d06..5427 8 days ago 1.21 GB
就像讀者看到的一樣,剛才拉取的鏡像已經存在于 Docker 主機本地倉庫中。同時可以看到 Windows 鏡像要遠大于 Linux 鏡像,鏡像中分層也更多。