Docker配置代理IP-下载镜像

1、创建docker.service.d目录

mkdir /etc/systemd/system/docker.service.d/

2、创建配置文件

cat >/etc/systemd/system/docker.service.d/http-proxy.conf <<'EOF'
[Service]
Environment="HTTP_PROXY=http://192.168.0.108:2335" "HTTPS_PROXY=http://192.168.0.108:2335"
EOF

NO_PROXY环境变量值: 主要配置不需要代理
http://192.168.0.108:2335 # 就是代理IP地址

3、配置daemon.json

master1 ~]# cat /etc/docker/daemon.json 
{
"data-root":"/data/docker",
"insecure-registries": ["192.168.10.33:80"],
"registry-mirrors": ["https://registry.k8s.io"],
"exec-opts": ["native.cgroupdriver=systemd"]
}

# 配置
registry-mirrors,把下载的仓库地址增加好

4、重启docker服务

systemctl daemon-reload 
systemctl restart docker

5、检查配置的环境变量是否生效

master1 ~]# systemctl show --property=Environment docker
Environment=HTTP_PROXY=http://192.168.0.108:2335 HTTPS_PROXY=http://192.168.0.108:2335

master1 ~]# docker info | grep -i proxy
 HTTP Proxy: http://192.168.0.108:2335
 HTTPS Proxy: http://192.168.0.108:2335

6、测试下载镜像

master1 ~]# docker pull registry.k8s.io/ingress-nginx/controller:v1.7.0@sha256:7612338342a1e7b8090bef78f2a04fffcadd548ccaabe8a47bf7758ff549a5f7
registry.k8s.io/ingress-nginx/controller@sha256:7612338342a1e7b8090bef78f2a04fffcadd548ccaabe8a47bf7758ff549a5f7: Pulling from ingress-nginx/controller
63b65145d645: Pull complete 
b4bea1ae47cc: Pull complete 
7416657d1589: Pull complete 
c9a4dd0b75c2: Pull complete 
1621aadd43dd: Pull complete 
4f4fb700ef54: Pull complete 
524510d39e1a: Pull complete 
ecfe47f2aaee: Pull complete 
49d820999ef3: Pull complete 
bdee9cd2eeaa: Pull complete 
8ff3f184df89: Pull complete 
b9f8a23ad5f3: Pull complete 
dcef9d94787d: Pull complete 
e81f57123d43: Pull complete 
Digest: sha256:7612338342a1e7b8090bef78f2a04fffcadd548ccaabe8a47bf7758ff549a5f7
Status: Downloaded newer image for registry.k8s.io/ingress-nginx/controller@sha256:7612338342a1e7b8090bef78f2a04fffcadd548ccaabe8a47bf7758ff549a5f7
registry.k8s.io/ingress-nginx/controller:v1.7.0@sha256:7612338342a1e7b8090bef78f2a04fffcadd548ccaabe8a47bf7758ff549a5f7

 

posted @ 2023-04-07 12:01  小粉优化大师  阅读(443)  评论(0编辑  收藏  举报