Docker:docker 拉取镜像及查看pull下来的image在哪里

本文详细介绍了如何配置Docker加速器以提高镜像拉取速度,通过具体步骤演示了如何从仓库下载镜像至本地,并展示了如何运行已下载的镜像。此外,还深入解析了Docker镜像的存储位置及查看方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一:拉取镜像

1、国内连接docker官网很慢修改docker中配置,添加对应中国docker加速器。

vi  /etc/docker/daemon.json
{
    "registry-mirrors": ["https://registry.docker-cn.com"],
    "live-restore": true
}

2、运行以下命令(本处以hello-world为例),将image文件从仓库拉去到本地。

docker pull library/hello-world

其中拉去命令为docker pull。hello-world为image为名称,library为hello-world镜像所在组。

执行完成后执行docker images可以查询。

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              4ab4c602aa5e        2 months ago        1.84kB
ubuntu              15.10               9b9cb95443b5        2 years ago         137MB

3、运行拉去成功的image,docker run XXX

docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

hello-world运行完成后会自动关闭,类似myssql这样的服务类image运行后不会自动关闭。可以执行docker stop imageName停止。

二、查看iamge位置

1、docker镜像保存在 /var/lib/docker/ 目录下

/var/lib/docker# ls
builder  buildkit  containerd  containers  image  network  overlay2  plugins  runtimes  swarm  tmp  trust  volumes

2、进入containerd目录可以查看相应iamge

/var/lib/docker/containers# ls
4dabf98c9d09234babaa8587e61c6e36e46788e68085df25813d91fdfcc0f990  c4707b15e72381c0f1a71959266397437bd91421d1a62c48213d1d012a875d89
a9dd7aeba4b2477bf0fcdaf7657ca66209d5d220caad1f331e1b053e5d3922ca  cfe45e1fb45ee40987b884e15db84c18e969e98a44c23332c0a40c9bd49cb6b1
bb2966bb77484e46dc91eef0983ccf7e747661e2f5f6248e11a60cbfa81a380c  e9486c384b6d00e65d6f43c856751ee47cc8af88b0b5238be1971b3ae6dfcbb1

3、.在containers同级目录,有个叫image的文件夹,进入后

cd images/aufs
 
distribution  imagedb  layerdb  repositories.json

在 repositories.json文件中记录了iamge的信息。


{"Repositories":{"hello-world":{"hello-world:latest":"sha256:4ab4c602aa5eed5528a6620ff18a1dc4faef0e1ab3a5eddeddb410714478c67f","hello-world@sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788":"sha256:4ab4c602aa5eed5528a6620ff18a1dc4faef0e1ab3a5eddeddb410714478c67f"},"ubuntu":{"ubuntu:15.10":"sha256:9b9cb95443b5f846cd3c8cfa3f64e63b6ba68de2618a08875a119c81a8f96698","ubuntu@sha256:02521a2d079595241c6793b2044f02eecf294034f31d6e235ac4b2b54ffc41f3":"sha256:9b9cb95443b5f846cd3c8cfa3f64e63b6ba68de2618a08875a119c81a8f96698"}}}

有些iamge文件夹下没有aufs目录,可能是这样的

/var/lib/docker/image# ls
overlay2

同样进入到overlay2文件夹下,可以看到aufs中相同的内容

/var/lib/docker/image/overlay2# ls
distribution  imagedb  layerdb  repositories.json

 

<think>我们正在处理用户的问题:“dockerpull nginx:latest如何配置国内镜像源”。根据引用内容,配置国内镜像源主要通过在Docker的配置文件中添加registry-mirrors来实现。引用[3]和引用[4]提供了具体的配置方法,其中引用[3]是在Ubuntu系统下修改/etc/docker/daemon.json文件,引用[4]也展示了类似的配置,但未说明操作系统,不过方法通用。步骤:1.编辑Docker的配置文件daemon.json(位置通常为/etc/docker/daemon.json)。如果文件不存在,可以创建。2.在文件中添加一个JSON对象,其中包含"registry-mirrors"键,其值为一个数组,包含多个国内镜像源的URL。3.保存文件后,重新加载配置并重启Docker服务。注意:不同的操作系统(如Windows、Linux)配置文件位置可能略有不同,但配置方式相同。具体操作:对于Linux系统(如Ubuntu):-使用命令编辑配置文件:`sudo vim /etc/docker/daemon.json`-将以下内容写入(以引用[4]中的镜像源为例,可选择一个或多个):{"registry-mirrors":["https://docker.m.daocloud.io","https://docker.nju.edu.cn","https://docker.mirrors.ustc.edu.cn","https://mirror.baidubce.com"]}-保存退出后,执行:sudosystemctldaemon-reloadsudo systemctl restartdocker对于Windows系统(使用DockerDesktop):-右键点击系统托盘中的Docker图标,选择“Settings”(或“设置”)。-在设置窗口中选择“Docker Engine”,在右侧的JSON配置框中添加或修改"registry-mirrors"项。-例如:"registry-mirrors":["https://docker.m.daocloud.io","https://docker.nju.edu.cn"]-点击“Apply &Restart”按钮应用并重启。配置完成后,即可使用`dockerpull nginx:latest`从国内镜像源快速镜像。注意:镜像源地址可能会变化,建议使用稳定可靠的镜像源。国内常用的镜像源包括阿里云、网易、中科大等。相关问题:1.如何验证Docker镜像源配置是否生效?2.镜像时出现超时错误怎么办?3.除了修改配置文件,还有其他方法加速Docker镜像吗?</think>### Docker 配置国内镜像 nginx:latest #### 配置步骤(Linux/Ubuntu 系统为例) 1. **修改 Docker 配置文件** 编辑 `/etc/docker/daemon.json` 文件(不存在则新建): ```bash sudo vim /etc/docker/daemon.json ``` 添加以下内容(以阿里云、中科大等国内镜像源为例): ```json { "registry-mirrors": [ "https://x9r52uz5.mirror.aliyuncs.com", // 阿里云 "https://docker.mirrors.ustc.edu.cn", // 中科大 "https://docker.nju.edu.cn" // 南京大学 ] } ``` 2. **重载配置并重启 Docker** ```bash sudo systemctl daemon-reload sudo systemctl restart docker ``` 3. **验证镜像源配置** ```bash docker info | grep "Registry Mirrors" # 查看生效的镜像源 ``` 4. ** nginx:latest 镜像** ```bash docker pull nginx:latest # 此时会从国内镜像源加速下载 ``` #### Windows/WSL 系统配置 1. **Docker Desktop 设置** - 右键托盘图标 → `Settings` → `Docker Engine` - 在 JSON 配置中添加 `"registry-mirrors"` 数组(同 Linux 配置) - 点击 `Apply & Restart` 2. **WSL 子系统配置** 在 WSL 终端中操作步骤与 Linux 一致(修改 `/etc/docker/daemon.json`)。 #### 常见问题解决 - **失败时**:尝试更换镜像源地址(如网易云 `https://hub-mirror.c.163.com`)。 - **配置文件权限问题**:确保 `/etc/docker/daemon.json` 权限为 `644`。 - **同步时间问题**:添加 `-v /etc/localtime:/etc/localtime` 到容器启动命令[^1]。 > **关键提示**:镜像源需定期更新,失效时可参考 [Docker 官方镜像加速文档](https://www.docker.com/blog/docker-hub-image-acceleration-in-china/)。 --- ### 相关问题 1. 如何验证 Docker 镜像源是否生效? 2. Docker 镜像时出现 `TLS handshake timeout` 错误如何解决? 3. 除了镜像源配置,还有哪些方法可以加速 Docker 镜像下载? [^1]: 引用[1]:docker下安装nginx:latest (1.21.6)。通过 `-v /etc/localtime` 同步宿主机和容器时间。 [^2]: 引用[2]:Dify部署:windows下docker配置镜像。Windows 系统通过 Docker Desktop 配置镜像源。 [^3]: 引用[3]:ubuntu 安装 docker pull 镜像。修改 `/etc/docker/daemon.json` 并重启服务。 [^4]: 引用[4]:解决docker镜像失败问题。添加多镜像源到 `registry-mirrors` 数组。
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值