Docker BUG排查

问题描述:

在刚安装完docker,执行sudo docker pull hello-world 来测试 docker 是否安装成功时,报错:

复制代码
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Retrying in 1 second 
docker: error pulling image configuration: download failed after attempts=6: dial tcp [2a03:2880:f130:83:face:b00c:0:25de]:443: i/o timeout.
See 'docker run --help'.

原因及解决方案:

Docker 守护进程作为一个后台服务运行,它并不会读取或继承用户的 shell 环境变量(除非在启动时特别指定)。为了确保 Docker 在拉取镜像或进行其他网络通讯时能够通过代理服务器,必须在 Docker 的服务配置中设置这些代理变量。

如果你的代理服务器运行在本地机器上,并且使用的端口是 7890,你需要在 Docker 的配置文件中设置这些代理参数以确保 Docker 通过这个本地代理端口进行网络通信。以下是具体的配置文件内容:

创建或编辑 /etc/systemd/system/docker.service.d/http-proxy.conf 文件

首先,你需要确保有一个目录来存放 Docker 的服务配置。如果这个目录还不存在,你可以使用以下命令创建它:

复制代码
sudo mkdir -p /etc/systemd/system/docker.service.d

接着,使用文本编辑器创建或编辑 http-proxy.conf 文件:

复制代码
sudo vim /etc/systemd/system/docker.service.d/http-proxy.conf

在打开的编辑器中,输入以下内容:

复制代码
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7890"
Environment="HTTPS_PROXY=http://127.0.0.1:7890"
Environment="NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com"

这里配置了 HTTP 和 HTTPS 代理都指向 127.0.0.17890 端口。NO_PROXY 环境变量指定了不需要通过代理访问的地址列表,通常包括本地地址和内部网络地址等。

保存并关闭编辑器

如果你使用的是 nano 编辑器,可以通过按 Ctrl+O 保存文件,然后按 Ctrl+X 退出编辑器。

如果用的是vim,则按esc键,然后输入:wq保存退出。

重新加载系统守护进程并重启 Docker 服务

为了让这些更改生效,你需要重新加载系统守护进程并重启 Docker 服务:

复制代码
sudo systemctl daemon-reload
sudo systemctl restart docker

这样,Docker 服务在启动和运行时就会使用本地的 7890 端口的代理服务器进行网络通信。可以通过尝试拉取一个 Docker 镜像来测试代理配置是否生效:

复制代码
sudo docker run hello-world

如果这个命令能够成功执行,并且能够从 Docker Hub 拉取镜像,那么就说明你的代理配置是正确的。如果遇到连接问题,需要检查本地代理服务器是否正常运行在指定端口上。

成功运行的输出:

复制代码
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:266b191e926f65542fa8daaec01a192c4d292bff79426f47300a046e1bc576fd
Status: Downloaded newer image for hello-world:latest

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

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
相关推荐
喵手24 分钟前
【探索实战】Kurator打造一栈式分布式云原生平台的实践与前瞻!
分布式·云原生·kurator·云原生平台
编码追梦人30 分钟前
【探索实战】Kurator:开启分布式云原生之旅
分布式·云原生
2501_941149509 小时前
探索云原生架构:从容器到微服务的全面升级
微服务·云原生·架构
喵了几个咪9 小时前
Kratos微服务轻松对接EFK日志系统
微服务·云原生·架构
小坏讲微服务15 小时前
Docker-compose搭建Docker Hub镜像仓库整合SpringBootCloud
运维·分布式·spring cloud·docker·云原生·容器·eureka
Serverless社区15 小时前
【本不该故障系列】从 runC 到 runD:SAE 如何化解安全泄露风险
阿里云·云原生·serverless
A懿轩A15 小时前
Sealos Devbox :从零搭建云原生开发环境
云原生·devbox·sealos devbox
2501_9411495016 小时前
区块链技术:从金融革命到行业变革的多维探索
eureka
清风一徐17 小时前
K8S环境中通过prometheus实现flink服务监控并给flink设置服务监测自动重启
linux·运维·云原生·容器·flink·kubernetes·prometheus
q***581918 小时前
springcloud-eureka与gateway简易搭建
spring cloud·eureka·gateway