docker拉取镜像操作

2023-12-18  本文已影响0人  mini鱼

拉取镜像

常规用法

$ docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
5ba4f30e5bea: Pull complete
9d7d19c9dc56: Pull complete
ac6ad7efd0f9: Pull complete
e7491a747824: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:46fb5d001b88ad904c5c732b086b596b92cfb4a4840a3abd0e35dbb6870585e4
Status: Downloaded newer image for ubuntu:latest

可以使用docker pull命令直接从Docker Hub镜像源来下载镜像。该命令的格式为docker pull NAME[:TAG]。其中,NAME是镜像仓库的名称(用来区分镜),TAG是镜像的标签(往往用来表示版本信息)。通常情况下,描述一个镜像需要包括“名称+标签”信息。

如果不显式指定TAG,则默认会选择latest标签,这会下载仓库中最新版本的镜像,一般来说,镜像的latest标签意味着该镜像的内容会跟踪最新的非稳定版本而发布,内容是不稳定的。从稳定性上考虑,不要在生产环境中忽略镜像的标签信息或使用默认的latest标记的镜像。

下载过程中可以看出,镜像文件一般由若干层(layer)组成,6c953ac5d795这样的串是层的唯一id(实际上完整的id包括256比特,由64个十六进制字符组成)。使用docker pull命令下载时会获取并输出镜像的各层信息。当不同的镜像包括相同的层时,本地仅存储层的一份内容,减小了需要的存储空间。

严格地讲,镜像的仓库名称中还应该添加仓库地址(即registry,注册服务器)作为前缀,只是我们默认使用的是Docker Hub服务,该前缀可以忽略。
例如,docker pull ubuntu:14.04命令相当于docker pull registry.hub.docker.com/ubuntu:14.04命令,即从默认的注册服务器Docker Hub Registry中的ubuntu仓库来下载标记为14.04的镜像。
如果从非官方的仓库下载,则需要在仓库名称前指定完整的仓库地址。例如从网易蜂巢的镜像源来下载ubuntu:14.04镜像,可以使用如下命令,此时下载的镜像名称为hub.c.163.com/public/ubuntu:14.04

已下载的镜像一般是存放在/var/lib/docker/image/overlay2目录下的 repositories.json文件中


image.png

拉取指定架构的镜像

docker pull --platform arm64 nginx
Using default tag: latest
latest: Pulling from library/nginx
latest: Pulling from library/nginx
24e221e92a36: Pull complete
dea6ff782824: Pull complete
b68aa9452119: Pull complete
7d7695f966cc: Pull complete
ecb8652230eb: Pull complete
df105b20a688: Pull complete
ff0d90dfb474: Pull complete
Digest: sha256:064a954fd07bc6468b490488cd0703837601f71a8931f440f3658ad387f5dee4
Status: Downloaded newer image for nginx:latest

如果报错,则需修改配置文件,重启docker服务

[root@localhost ~]# docker pull --platform arm64 nginx
"--platform" is only supported on a Docker daemon with experimental features enabled

在/etc/docker/daemon.json中添加"experimental": true,如图:


image.png
上一篇 下一篇

猜你喜欢

热点阅读