Skip to content

Commit

Permalink
feat: 更新安装Docker从清华源
Browse files Browse the repository at this point in the history
  • Loading branch information
fishros committed Aug 28, 2024
1 parent 01c5cb5 commit 6d31947
Showing 1 changed file with 26 additions and 37 deletions.
63 changes: 26 additions & 37 deletions tools/tool_install_docker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from .base import BaseTool
from .base import PrintUtils,CmdTask,FileUtils,AptUtils,ChooseTask
from .base import osversion,osarch
from .base import PrintUtils, CmdTask, FileUtils, AptUtils, ChooseTask
from .base import osversion, osarch
from .base import run_tool_file

class Tool(BaseTool):
Expand All @@ -12,54 +12,43 @@ def __init__(self):

def install_docker(self):
"""
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
Executing Docker install script with updated commands for new installation steps.
"""
PrintUtils.print_info("开始根据系统架构,为你下载对应版本的docker~")

# 更换系统源
# dic = {1:"更换系统源再继续安装",2:"不更换继续安装"}
# code,result = ChooseTask(dic, "如果您是第一次安装,推荐您先更换一下系统源").run()
# if code==1:
# run_tool_file('tools.tool_config_system_source')

# check apt
if not AptUtils.checkapt(): return False
# Check if apt is available
if not AptUtils.checkapt():
return False

#pre-install
CmdTask('sudo apt install apt-transport-https ca-certificates curl software-properties-common -y',120).run()
# Pre-installation steps
CmdTask('apt-get update', 120, os_command=True).run()
CmdTask('DEBIAN_FRONTEND=noninteractive apt-get install -y ca-certificates curl ', 120, os_command=True).run()
CmdTask('install -m 0755 -d /etc/apt/keyrings', 10, os_command=True).run()

#add key
CmdTask('curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -',10).run()
#verify key
CmdTask('sudo apt-key fingerprint 0EBFCD88',10).run()
if osarch=="bullseye":
CmdTask("curl -fsSL https://get.docker.com -o get-docker.sh").run()
CmdTask("sudo sh get-docker.sh").run()
PrintUtils.print_info("安装完成,接下来你可以尝试使用docker --version指令测试是有正常回显~")
return
# Add Docker GPG key
CmdTask('curl -fsSL "https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg" -o /etc/apt/keyrings/docker.asc', 10, os_command=True).run()
CmdTask('chmod a+r /etc/apt/keyrings/docker.asc', 10,os_command=True).run()

# 根据系统架构下载不同版本的安装包
if osarch=='amd64':
CmdTask('sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" -y',os_command=True).run()
elif osarch=='arm64':
CmdTask('sudo add-apt-repository "deb [arch=arm64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" -y',os_command=True).run()
# Add Docker repository
if osarch == 'amd64':
CmdTask('echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list', os_command=True).run()
elif osarch == 'arm64':
CmdTask('echo "deb [arch=arm64 signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list', os_command=True).run()
else:
return False

# Update apt index and install Docker
PrintUtils.print_info("下载完成,接下来升级apt索引~")
CmdTask("sudo apt update").run()
CmdTask('apt-get update ', 10,os_command=True).run()
PrintUtils.print_info("开始安装最新版本docker CE~")
CmdTask("sudo apt --fix-broken install -y").run()
# CmdTask("sudo apt install docker-ce -y").run()
AptUtils.install_pkg_check_dep("docker-ce")
CmdTask("sudo groupadd docker").run()
CmdTask('DEBIAN_FRONTEND=noninteractive apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin', 120,os_command=True).run()

# Post-installation steps
CmdTask('sudo groupadd docker', 10,os_command=True).run()
user = FileUtils.getusers()[0]
CmdTask("sudo gpasswd -a {} docker".format(user)).run()
# CmdTask("newgrp docker",os_command=True).run()
CmdTask('sudo gpasswd -a {} docker'.format(user), 10,os_command=True).run()

PrintUtils.print_info("安装完成,接下来你可以尝试使用docker --version指令测试是有正常回显~")

def run(self):
self.install_docker()

0 comments on commit 6d31947

Please sign in to comment.