Ubuntu Server 24.04 LTS 安装 Docker 与 Docker Compose
1. 更新源
sudo apt update
2. 安装一些用于 HTTPS 的软件包
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
3. 设置 Docker 源
Docker 官方
# 添加 Docker 官方 GPG 密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# 设置 Docker 官方源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
阿里云
# 添加阿里云 GPG 密钥
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# 设置阿里云源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
4. 更新源
sudo apt update
5. 安装 Docker 与 Docker Compose
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
6. 启动 Docker
sudo systemctl start docker
7. 设置 Docker 开机自动启动
sudo systemctl enable docker.service
8. 验证 Docker 是否安装成功
docker --version
9. 添加用户到 Docker 组
# 需要重新登录使组更改生效
sudo usermod -aG docker $USER