配置docker的proxy指向

因为网络原因,现在无法直接下载docker hub上的镜像,需设置通过proxy进行访问。

一、测试环境

在笔记本上启用了proxy软件,笔记本IP为192.168.253.1,proxy端口8888。搭建一台Linux虚拟机用于下载docker镜像,虚拟机IP:192.168.253.129

二、修改docker配置文件

修改虚拟机内docker配置文件/lib/systemd/system/docker.service,指向代理服务程序端口。

需要在Service小段中增加:

Environment="HTTP_PROXY=http://192.168.253.1:8888"

Environment="HTTPS_PROXY=http://192.168.253.1:8888"

如下:

bash 复制代码
[root@localhost ~]# vi /lib/systemd/system/docker.service
[root@localhost ~]# cat /lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
Environment="HTTP_PROXY=http://192.168.253.1:8888"
Environment="HTTPS_PROXY=http://192.168.253.1:8888"
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash

ExecStart=/usr/bin/dockerd $OPTIONS \
                           $DOCKER_STORAGE_OPTIONS \
                           $DOCKER_NETWORK_OPTIONS \
                           $INSECURE_REGISTRY
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process

[Install]
WantedBy=multi-user.target

三、重启服务进行验证

bash 复制代码
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker             
[root@localhost ~]# docker pull minio/minio:latest       
latest: Pulling from minio/minio
55360c0b72d6: Pull complete 
f2f8f30a646a: Pull complete 
4fc5fcb7e9ca: Pull complete 
53140b7a7f04: Pull complete 
2b8c182be72c: Pull complete 
4363be478988: Pull complete 
de7c323e2901: Pull complete 
7eb10b7b511b: Pull complete 
3d82d69301e2: Pull complete 
Digest: sha256:cd04ea408e185cb50076ea1c3988d444119b19aaae15aab45387ccf14b2a2f86
Status: Downloaded newer image for minio/minio:latest
[root@localhost ~]# 

可以看到,已能正常下载容器镜像,使用网络proxy也可参照配置。

相关推荐
切糕师学AI几秒前
NAT (Network Address Translation,网络地址转换)
运维·服务器·网络
x-cmd10 分钟前
Browser-Use:用自然语言控制浏览器,告别脆弱的自动化脚本
运维·ai·自动化·agent·浏览器·x-cmd
only_Klein29 分钟前
Kubernetes-deployment控制器
云原生·容器·kubernetes
AC赳赳老秦35 分钟前
软件组件自动化的革命:DeepSeek 引领高效开发新时代
运维·人工智能·算法·云原生·maven·devops·deepseek
之歆35 分钟前
LVS 负载均衡完全指南
运维·负载均衡·lvs
Web极客码1 小时前
用 SSH Key 认证提升文件传输安全:SFTP/SSH 加固实战(适合站点运维与外贸站)
运维·安全·ssh
zhojiew1 小时前
在中国区EKS集群使用 kgateway 代理 Lambda 函数的实践过程
运维·envoy
Channing Lewis1 小时前
为什么部署的项目会耗尽系统句柄
服务器
小李独爱秋2 小时前
模拟面试:什么是容器技术,Docker是什么?
运维·docker·容器·面试·职场和发展
山峰哥3 小时前
SQL调优实战:从索引失效到性能飙升的破局之道
服务器·数据库·sql·性能优化·编辑器·深度优先