配置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也可参照配置。

相关推荐
DolitD5 小时前
3D应用多实例并发中的GPU隔离技术路径分析
容器·gru·接口隔离原则
Lsetea5 小时前
curl报58 unable to set private key file:客户端证书与私钥加载排查
运维·https·ssl证书·openssl·curl
天远Date Lab5 小时前
零信任架构实战:基于天远学籍核验三要素构建自动化竞赛资格审查网关
运维·人工智能·架构·自动化
KING-WU5125 小时前
Linux 工具之Make 与 Makefile
java·linux·服务器
阿乔外贸日记5 小时前
全球电子产业高度集中:中、韩、日和中国台湾地区占全球数字硬件产能八成
大数据·服务器·人工智能·物联网·云计算
Lsetea6 小时前
OpenSSL报certificate is not yet valid:error 9与notBefore时间排查
linux·运维·https·ssl证书·openssl
魔法阵维护师6 小时前
Linux 命令行入门踩坑记录:从 VMware 装系统到文件管理
linux·运维·服务器
飞飞传输6 小时前
业务系统文件安全检测怎么做?生物医药企业选型与建设指南
大数据·运维·安全
姜鱼问生6 小时前
docker exec 排查容器问题:从日志到进程
运维·网络·数据库·docker·容器
qq_543447826 小时前
DNS解析怎么排查?故障处理与运维实用手册
运维·服务器·网络·php