Skip to content

Commit

Permalink
feat: 添加一键配置Docker代理
Browse files Browse the repository at this point in the history
  • Loading branch information
fishros committed Jul 7, 2024
1 parent 53555e9 commit 10b6655
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
14: {'tip':'一键安装:科学上网代理工具','type':INSTALL_SOFTWARE,'tool':url_prefix+'tools/tool_install_proxy_tool.py' ,'dep':[8] },
15: {'tip':'一键安装:QQ for Linux', 'type':INSTALL_SOFTWARE, 'tool': url_prefix+'tools/tool_install_qq.py', 'dep':[]},
16: {'tip':'一键安装:系统自带ROS (!!警告!!仅供特殊情况下使用)', 'type':INSTALL_ROS, 'tool': url_prefix+'tools/tool_install_ros1_systemdefault.py', 'dep':[5]},
17: {'tip':'一键配置: Docker代理(支持VPN+代理服务两种模式)', 'type':CONFIG_TOOL, 'tool': url_prefix+'tools/tool_config_docker_proxy.py', 'dep':[]},
# 77: {'tip':'测试模式:运行自定义工具测试'},
}
#
Expand Down
56 changes: 56 additions & 0 deletions tools/tool_config_docker_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
from .base import BaseTool
from .base import PrintUtils,CmdTask,FileUtils,AptUtils,ChooseTask
from .base import osversion,osarch
from .base import run_tool_file



class Tool(BaseTool):
def __init__(self):
self.name = "一键配置Docker代理(支持VPN+代理服务两种模式)"
self.type = BaseTool.TYPE_INSTALL
self.autor = '小鱼'


def config_docker_proxy(self):


dic = {1:"VPN模式(需要本地有支持HTTP代理)",2:"服务模式(需要提供支持Docker代理的服务器地址)",3:"删除所有模式代理"}
code,result = ChooseTask(dic, "请选择代理模式,如果不清楚可以选2").run()
# 根据系统架构下载不同版本的安装包
if code==1:
url = input('请输入代理所在地址(直接回车使用:127.0.0.1):')
if not url:
url = '127.0.0.1'
port = input('请输入代理所在端口:')
proxy_config_vpn = f"""[Service]
Environment="HTTP_PROXY=http://{url}:{port}/"
Environment="HTTPS_PROXY=http://{url}:{port}/"
Environment="NO_PROXY=localhost,127.0.0.1,{url},.example.com"""
FileUtils.new('/etc/systemd/system/docker.service.d/','proxy.conf',proxy_config_vpn)
PrintUtils.print_info(f"在{'/etc/systemd/system/docker.service.d'}/{'proxy.conf'}写入了{proxy_config_vpn},接下来为你重启Docker!")
CmdTask("sudo systemctl daemon-reload").run()
CmdTask("sudo systemctl restart docker").run()
elif code==2:
url = input('请输入代理网址(直接回车将进入选择界面):')
if not url:
dic = {1:"https://dockerpull.com",2:"https://docker.fxxk.dedyn.io",3:"https://ac77d18f43e44819b553040f294b8f9b.mirror.swr.myhuaweicloud.com"}
code,result = ChooseTask(dic, "请选择代理加速网址").run()
url = dic[code]
print(url)
proxy_config_vpn = f'{{"registry-mirrors": ["{url}"]}}'
FileUtils.new('/etc/docker/','daemon.json',proxy_config_vpn)
PrintUtils.print_info(f"在{'/etc/docker/'}/{'daemon.json'}写入了{proxy_config_vpn},接下来为你重启Docker!")
CmdTask("sudo systemctl daemon-reload").run()
CmdTask("sudo systemctl restart docker").run()
elif code==3:
CmdTask("sudo rm /etc/systemd/system/docker.service.d/proxy.conf").run()
CmdTask("sudo rm /etc/docker/daemon.json").run()
CmdTask("sudo systemctl daemon-reload").run()
CmdTask("sudo systemctl restart docker").run()
PrintUtils.print_info("配置完成,接下来你可以尝试再次拉取镜像了~")

def run(self):
self.config_docker_proxy()

0 comments on commit 10b6655

Please sign in to comment.