跳至主要內容

Debian部署

五六零网校大约 1 分钟

一键安装Docker和docker-compose

  1. 创建脚本文件install_docker.sh

install_docker.sh脚本内容:

#!/bin/bash

# Debian 12系统初始化和Docker安装脚本

# 更新软件包列表
sudo apt update

# 安装基本依赖
sudo apt install -y curl apt-transport-https ca-certificates gnupg lsb-release bc

# 测试镜像延迟并选择最佳镜像
lowest_latency=-1
selected_mirror=""
for script_url in "https://get.docker.com" "https://mirrors.aliyun.com/docker-ce/linux/debian/gpg" "https://download.docker.com/linux/debian/gpg"; do
  latency=$(ping -c 3 -q "$script_url" 2>&1 | awk -F/ 'END{print $5}')
  if [[ $lowest_latency == -1 || $(echo "$latency < $lowest_latency" | bc -l) -eq 1 ]]; then
    lowest_latency="$latency"
    selected_mirror="$script_url"
  fi
done

# 输出选择的最佳镜像
echo "选择的镜像: $selected_mirror"

# 执行Docker安装脚本
curl -fsSL "$selected_mirror" | sudo bash

# 安装Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-Linux-x86_64" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

# 输出安装完成信息
echo "Docker和Docker Compose安装完成。"

  1. 终端执行安装命令
chmod +x install_docker.sh
./install_docker.sh
  1. 检查安装
Docker -v
docker compose version

手动安装Docker

提示

本篇教程为Debian系统专用,请确认你当前的系统

1. 更新软件包列表

sudo apt update

2. 安装依赖项,以支持 HTTPS 下载

sudo apt install apt-transport-https ca-certificates curl software-properties-common

3. 添加 Docker GPG 密钥

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

4. 设置 Docker APT 存储库

echo "deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

5. 安装 Docker

sudo apt update
sudo apt install docker-ce

6. 启动 Docker 服务

sudo systemctl start docker

7. 验证 Docker 安装

sudo docker --version

安装Docker Compose

1. 下载 Docker Compose 二进制文件

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

2. 赋予执行权限

sudo chmod +x /usr/local/bin/docker-compose

3. 验证 Docker Compose 安装

docker-compose --version