暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

docker pull nginx:1.17 net/http: request canceled while waiting for connection

章芋文 2025-09-09
553

最近在替换ssl证书,重建nginx容器时,报错Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

[root@ecs-1 nginx]# docker build -t modb/nginx:prod . Sending build context to Docker daemon 62.98kB Step 1/10 : FROM nginx:1.17 Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

临时解决方案

这里直接原因就是网络不通的原因,尝试更换了nameserver无效,在不重启服务的情况下临时方案如下:

docker cp ./ssl/. nginx:/etc/nginx/ssl/ docker exec nginx nginx -s reload

也就是手工将ssl文件cp到容器内,然后reload nginx即可。

国内镜像加速

最优解决方案还是设置国内镜像加速,这一步要重启容器。可以使用免费的镜像,我这里使用的华为云的镜像加速地址,
在你的 ECS 上,创建或修改 /etc/docker/daemon.json:

{ "registry-mirrors": [ "https://<your-id>.mirror.swr.myhuaweicloud.com" ] }

⚠️ 需要替换成控制台显示的专属加速地址,可以在https://console.huaweicloud.com/swr/登陆后查看。

重启docker

systemctl daemon-reload systemctl restart docker

成功重建

[root@ecs-1 nginx]# docker build -t modb/nginx:prod . Sending build context to Docker daemon 62.98kB Step 1/10 : FROM nginx:1.17 1.17: Pulling from library/nginx Digest: sha256:6fff55753e3b34e36e24e37039ee9eae1fe38a6420d8ae16ef37c92d1eb26699 Status: Downloaded newer image for nginx:1.17 ---> a48d4f95ac74 Step 2/10 : RUN apt-get update && apt-get install -y libencode-perl libdbi-perl default-mysql-client fcgiwrap libhtml-parser-perl spawn-fcgi ---> Using cache ---> 04efc22e7329 Step 3/10 : EXPOSE 80 443 8123 8880 ---> Using cache ---> a3eac58d6eb5 Step 4/10 : VOLUME /u01 ---> Using cache ---> 4cc0f8f422f4 Step 5/10 : ADD nginx.conf /etc/nginx/nginx.conf ---> Using cache ---> 761cba90aa99 Step 6/10 : ADD fcgi-init.sh /opt/fcgi-init.sh ---> Using cache ---> f20106589fd3 Step 7/10 : RUN rm -rf /etc/nginx/conf.d/default.conf ---> Using cache ---> 06972b4e6696 Step 8/10 : COPY 443.*.conf /etc/nginx/conf.d/ ---> Using cache ---> e84e508e9066 Step 9/10 : COPY ./ssl/* /etc/nginx/ssl/ ---> 8f653c0b8c6d Step 10/10 : CMD ["sh", "/opt/fcgi-init.sh"] ---> Running in 64c1898c75b1 Removing intermediate container 64c1898c75b1 ---> 902fca5735a0 Successfully built 902fca5735a0 Successfully tagged modb/nginx:prod [root@ecs-1 nginx]#
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论