ubuntu22.04安装docker
#!/bin/bash
set -e
# 更新 apt 索引
apt update
# 安装必要的依赖包
apt install -y \
ca-certificates \
curl \
gnupg \
lsb-release \
apt-transport-https \
software-properties-common
# 创建 keyrings 目录
mkdir -p /etc/apt/keyrings
# 添加 Docker 官方 GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# 添加 Docker apt 软件源
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null
# 更新 apt 索引
apt update
# 安装 Docker Engine、CLI、containerd 以及 Compose 插件
apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
# 启动并设置开机自启
systemctl enable docker
systemctl start docker
# 测试 Docker 是否安装成功
docker --version