docker pull error with proxy

最近使用Linux挂载*X,可以正常登录网页,但是docker pull的时候,持续报错"Get https://registry-1.docker.io/v2/: net/http:request conceled while waiting for connection (Client.Timeout exceeded while awaiting headers)"
原因是docker的流量没有走全局代理,因此需要设置下环境。

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo vim /etc/systemd/system/docker.service.d/http-proxy-conf

# add following contents
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:10871"
Environment="HTTPS_PROXY=https://127.0.0.1:10871"

# then restart docker
sudo systemctl daemon-reload
sudo systemctl restart docker

如此就可以了,另外,也可以将环境变量加入~/.bashrc当中,方便其他软件使用

vim ~/.bashrc

# add following contents
Environment="HTTP_PROXY=http://127.0.0.1:10871"
Environment="HTTPS_PROXY=https://127.0.0.1:10871"

source ~/.bashrc

此外,在运行docker的时候,最好能直接指定templateflow,这样避免网络错误,example 如下:

 docker run -ti --rm \
    -v /home/clancy/ssd:/work \
    -u $(id -u):$(id -g) \
    -v /home/clancy/TemplateFlow:/opt/templateflow \
    -e TEMPLATEFLOW_HOME=/opt/templateflow \
    nipreps/fmriprep:24.1.1 \
    /work/BIDS/ /work/fmriprep/ participant \
    xxxxxxxxx
上一篇:组合计数