Configuration of docker pull when surfing the Internet through a proxy

Configuration of docker pull when surfing the Internet through a proxy

1 Introduction

When Docker is installed and the image is pulled, the following error is reported:

[root@localhost docker]# docker pull hub.c.163.com/public/centos:6.5
Error response from daemon: Get https://hub.c.163.com/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

2. Solve

# 1) 创建目录
mkdir -p /etc/systemd/system/docker.service.d

# 2) 创建http-proxy.conf配置文件
touch /etc/systemd/system/docker.service.d/http-proxy.conf
vim   /etc/systemd/system/docker.service.d/http-proxy.conf

## 在http-proxy.conf文件中添加如下内容 (根据自家的代理情况填写,参考资料有HTTPS的说明)
[Service]
Environment="HTTP_PROXY=http://192.168.1.3:80/" "NO_PROXY=localhost,127.0.0.1"

# 3) Flush变更
systemctl daemon-reload

# 4) 重启Docker
systemctl restart docker

# 5) 验证配置是否已加载
systemctl show --property=Environment docker
## 当有如下输出
Environment=HTTP_PROXY=http://192.168.1.3:80/ NO_PROXY=localhost,127.0.0.1

# 6) 拉取测试,如下
[root@localhost docker]# docker pull hello-world:latest
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest

problem solved!

Reference

Guess you like

Origin blog.csdn.net/hylaking/article/details/88052744