背景在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)
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
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://127.0.0.1:7890
procd_set_param env HTTPS_PROXY=http://127.0.0.1:7890
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://127.0.0.1:7890
procd_set_param env HTTPS_PROXY=http://127.0.0.1:7890
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
}
当前还没有任何评论