您现在的位置是:首页 >其他 >docker 解析DNS失败网站首页其他

docker 解析DNS失败

禹鼎侯 2024-07-02 00:01:02
简介docker 解析DNS失败

问题现象:

我之前在docker里部署的容器,今天突然访问不了了,一开始我以为是容器的问题,将容器restart,销毁重建,都没有解决。
最后准备重启docker service,在重启之前,看了一眼docker的状态:

ck94 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2023-04-25 10:06:23 CST; 1 months 3 days ago
     Docs: https://docs.docker.com
 Main PID: 2615 (dockerd)
    Tasks: 172
   Memory: 8.3G
   CGroup: /system.slice/docker.service
           ├─ 2615 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           ├─ 5610 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 55433 -container-ip 172.17.0.3 -container-port 5432
           ├─ 5627 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 55433 -container-ip 172.17.0.3 -container-port 5432
           ├─ 5671 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3000 -container-ip 172.17.0.4 -container-port 3000
           ├─ 5698 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 3000 -container-ip 172.17.0.4 -container-port 3000
           ├─21981 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9200 -container-ip 172.20.0.2 -container-port 9200
           ├─21994 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 9200 -container-ip 172.20.0.2 -container-port 9200
           ├─23558 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 10086 -container-ip 172.20.0.3 -container-port 9000
           ├─23575 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 10086 -container-ip 172.20.0.3 -container-port 9000
           ├─23624 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 38080 -container-ip 172.20.0.4 -container-port 8080
           ├─23640 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 38080 -container-ip 172.20.0.4 -container-port 8080
           ├─26535 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 49001 -container-ip 172.17.0.2 -container-port 9001
           ├─26552 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 49001 -container-ip 172.17.0.2 -container-port 9001
           ├─26602 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 49000 -container-ip 172.17.0.2 -container-port 9000
           ├─26620 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 49000 -container-ip 172.17.0.2 -container-port 9000
           ├─39170 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5601 -container-ip 172.20.0.5 -container-port 5601
           └─39182 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 5601 -container-ip 172.20.0.5 -container-port 5601

May 29 09:24:38 ck94 dockerd[2615]: time="2023-05-29T09:24:38.161269040+08:00" level=warning msg="[resolver] failed to read from DNS server: 223.6.6.6:53, query: ;elasticse... i/o timeout"
May 29 09:26:22 ck94 dockerd[2615]: time="2023-05-29T09:26:22.679628216+08:00" level=warning msg="[resolver] failed to read from DNS server: 223.6.6.6:53, query: ;elasticse... i/o timeout"
May 29 09:26:27 ck94 dockerd[2615]: time="2023-05-29T09:26:27.683446445+08:00" level=warning msg="[resolver] failed to read from DNS server: 223.6.6.6:53, query: ;elasticse... i/o timeout"
May 29 09:27:38 ck94 dockerd[2615]: time="2023-05-29T09:27:38.328922576+08:00" level=warning msg="ShouldRestart failed, container will not be restarted" container=4af5eb860cbfea8961372e...
May 29 09:34:18 ck94 dockerd[2615]: time="2023-05-29T09:34:18.236630475+08:00" level=warning msg="[resolver] failed to read from DNS server: 223.6.6.6:53, query: ;elasticse... i/o timeout"
May 29 09:35:02 ck94 dockerd[2615]: time="2023-05-29T09:35:02.949012103+08:00" level=warning msg="ShouldRestart failed, container will not be restarted" container=9969a986040d0f91bc80d9...
May 29 09:36:23 ck94 dockerd[2615]: time="2023-05-29T09:36:23.261658623+08:00" level=warning msg="[resolver] failed to read from DNS server: 223.6.6.6:53, query: ;elasticse... i/o timeout"
May 29 09:37:48 ck94 dockerd[2615]: time="2023-05-29T09:37:48.429139761+08:00" level=warning msg="[resolver] failed to read from DNS server: 223.6.6.6:53, query: ;elasticse... i/o timeout"
May 29 09:39:50 ck94 dockerd[2615]: time="2023-05-29T09:39:50.051518136+08:00" level=warning msg="[resolver] failed to read from DNS server: 223.6.6.6:53, query: ;elasticse... i/o timeout"
May 29 09:43:18 ck94 dockerd[2615]: time="2023-05-29T09:43:18.733473159+08:00" level=warning msg="[resolver] failed to read from DNS server: 223.6.6.6:53, query: ;elasticse... i/o timeout"
Hint: Some lines were ellipsized, use -l to show in full.

里面报大量的DNS解析错误。
我尝试在不同机器上curl该容器的url,在本机执行:

ck94 ~]# curl http://192.168.101.94:49001/browser
<!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="/"/><meta content="width=device-width,initial-scale=1" name="viewport"/><meta content="#081C42" media="(prefers-color-scheme: light)" name="theme-color"/><meta content="#081C42" media="(prefers-color-scheme: dark)" name="theme-color"/><meta content="MinIO Console" name="description"/><meta name="minio-license" content="agpl" /><link href="./styles/root-styles.css" rel="stylesheet"/><link href="./apple-icon-180x180.png" rel="apple-touch-icon" sizes="180x180"/><link href="./favicon-32x32.png" rel="icon" sizes="32x32" type="image/png"/><link href="./favicon-96x96.png" rel="icon" sizes="96x96" type="image/png"/><link href="./favicon-16x16.png" rel="icon" sizes="16x16" type="image/png"/><link href="./manifest.json" rel="manifest"/><link color="#3a4e54" href="./safari-pinned-tab.svg" rel="mask-icon"/><title>MinIO Console</title><script defer="defer" src="./static/js/main.5efdfa93.js"></script><link href="./static/css/main.57e739f5.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"><div id="preload"><img src="./images/background.svg"/> <img src="./images/background-wave-orig2.svg"/></div><div id="loader-block"><img src="./Loader.svg"/></div></div></body></html>

是没有问题的。
我在其他机器上执行:

chenyanchang@chenyanchangdeMacBook-Pro ~ % curl http://192.168.101.94:49001/browser
curl: (7) Failed to connect to 192.168.101.94 port 49001: Operation timed out

解决方案

重启docker服务,重启docker0网卡:

service docker stop
ip link set dev docker0 down
ip link set dev docker0 up
service docker start

再次查看, 问题解决:
在这里插入图片描述


推荐一个零声学院免费教程,个人觉得老师讲得不错,分享给大家:[Linux,Nginx,ZeroMQ,MySQL,Redis,
fastdfs,MongoDB,ZK,流媒体,CDN,P2P,K8S,Docker,
TCP/IP,协程,DPDK等技术内容,点击立即学习: C/C++Linux服务器开发/高级架构师

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。