From 18769447865eb9a55694562846459e5766c46619 Mon Sep 17 00:00:00 2001 From: Dcrclub Date: Thu, 24 Jul 2025 21:43:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=9B=BD=E5=86=85docker?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 9060fb6..0d1c59b 100644 --- a/install.sh +++ b/install.sh @@ -58,22 +58,22 @@ update_package_manager() { elif [[ "$OS" == *"CentOS"* ]] || [[ "$OS" == *"Red Hat"* ]] || [[ "$OS" == *"Rocky"* ]] || [[ "$OS" == *"AlmaLinux"* ]]; then if command -v dnf &> /dev/null; then dnf update -y - dnf install -y curl wget + dnf install -y curl wget jq else yum update -y - yum install -y curl wget + yum install -y curl wget jq fi else print_message "使用通用方式安装curl和wget..." # 尝试通用方式安装 if command -v apt &> /dev/null; then - apt update && apt install -y curl wget + apt update && apt install -y curl wget jq elif command -v dnf &> /dev/null; then - dnf install -y curl wget + dnf install -y curl wget jq elif command -v yum &> /dev/null; then - yum install -y curl wget + yum install -y curl wget jq elif command -v zypper &> /dev/null; then - zypper install -y curl wget + zypper install -y curl wget jq else print_warning "无法自动安装curl和wget,请手动安装" fi @@ -141,8 +141,49 @@ install_docker_compose() { ln -sf /usr/local/bin/docker-compose /usr/bin/docker-compose } +# 写入JSON配置文件的函数(更安全) +write_json_config() { + local file_path="$1" + local json_content="$2" + + mkdir -p "$(dirname "$file_path")" + + if command -v jq &> /dev/null; then + if echo "$json_content" | jq . > /dev/null 2>&1; then + print_message "JSON格式验证通过" + else + print_error "JSON格式无效" + return 1 + fi + fi + + echo "$json_content" | tee "$file_path" > /dev/null + + if [ $? -eq 0 ]; then + print_message "成功写入JSON配置文件: $file_path" + else + print_error "写入JSON配置文件失败: $file_path" + return 1 + fi +} + # 验证安装 verify_installation() { + # 修改国内的docker源 + local docker_daemon_config='{ + "registry-mirrors": [ + "https://docker.1panel.live", + "https://docker.1ms.run", + "https://docker.m.daocloud.io", + "https://registry.cn-hangzhou.aliyuncs.com" + ] + }' + + write_json_config "/etc/docker/daemon.json" "$docker_daemon_config" + + systemctl daemon-reload + systemctl restart docker + print_message "验证安装..." if command -v docker &> /dev/null; then