Docker 配置 HTTP 代理

只需修改 Docker 守护进行的配置文件 /usr/lib/systemd/system/dockerd.service,即可实现 docker 拉取镜像时走 http 代理。

gcr.io 的镜像,妥妥的。

在 配置文件( /usr/lib/systemd/system/dockerd.service)中追加一行 Environment

[Unit]
Description=dockerd

[Service]
Environment=QCLOUD_NORM_URL=
Type=notify
ExecStart=/usr/bin/dockerd --config-file=/etc/docker/daemon.json
ExecStartPre=/bin/rm -f /var/run/docker.pid
ExecStartPost=-/sbin/iptables -P FORWARD ACCEPT
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=always
RestartSec=10
Environment=http_proxy=http://10.0.0.15:27070 https_proxy=http://10.0.0.15:27070

[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

重新加载 dockerd.service

systemctl daemon-reload
1

重启 dockerd

systemctl restart dockerd
1

docker pull 一个 gcr.io 镜像试一下,so easy.

# docker pull gcr.io/kfserving/kfserving-controller:v0.6.0
v0.6.0: Pulling from kfserving/kfserving-controller
b49b96595fd4: Pull complete
38d58ce201a6: Pull complete
5583e9538b71: Pull complete
Digest: sha256:b57a6ee95204c6187f13128219f810e0a7b08b5bb4a0207c61aea09d1782e672
Status: Downloaded newer image for gcr.io/kfserving/kfserving-controller:v0.6.0
1
2
3
4
5
6
7

批量同步到所有 K8S 节点上

ansible hadoop -m copy -a "src=/usr/lib/systemd/system/dockerd.service dest=/usr/lib/systemd/system/dockerd.service"

ansible hadoop -m shell -a 'md5sum /usr/lib/systemd/system/dockerd.service'

ansible hadoop -m shell -a 'systemctl daemon-reload'

ansible hadoop -m shell -a 'systemctl restart dockerd'
1
2
3
4
5
6
7

reference