非原创,原文链接:loveyu.org/6115.html
背景:在openwrt上的docker拉取失败,提示如下错误:
root@openwrt:\~ # docker pull debian
Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
尝试的错误解决方法(一顿乱搜,AI极具误导性)
- 修改
/etc/docker/daemon.json
无效,还尝试了一下,以为可以,实际乱写的(AI方案) /etc/systemd/system/docker.service.d/http-proxy.conf
新增配置,一看就不可行,都没有 systemd- 修改
/etc/init.d/dockerd
添加 环境变量(AI方案),解决了一半,设置变量方式错了
最终有效方案
修改 /etc/init.d/dockerd
使用 procd_set_param env
设置环境变量
原脚本
start\_service() {
local nofile\=\$(cat /proc/sys/fs/nr\_open)
process\_config
procd\_open\_instance
procd\_set\_param stderr 1
if [ -z "\${DOCKERD\_CONF}" ]; then
procd\_set\_param command /usr/bin/dockerd
else
procd\_set\_param command /usr/bin/dockerd --config-file\="\${DOCKERD\_CONF}"
fi
procd\_set\_param limits nofile\="\${nofile} \${nofile}"
procd\_close\_instance
}
修改后的脚本
start\_service() {
local nofile\=\$(cat /proc/sys/fs/nr\_open)
process\_config
procd\_open\_instance
# set proxy
procd\_set\_param env HTTP\_PROXY\=http://xxx.x.x.x.:xxxx
procd\_set\_param env HTTPS\_PROXY\=http://xxx.x.x.x.:xxxx
procd\_set\_param stderr 1
if [ -z "\${DOCKERD\_CONF}" ]; then
procd\_set\_param command /usr/bin/dockerd
else
procd\_set\_param command /usr/bin/dockerd --config-file\="\${DOCKERD\_CONF}"
fi
procd\_set\_param limits nofile\="\${nofile} \${nofile}"
procd\_close\_instance
}
参考
标签:set,procd,nofile,param,拉取,dockerd,docker,openwrt From: https://www.cnblogs.com/drcode/p/18518140/openwrt-set-docker-proxy