1. 安装 Docker 依赖项
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release
2. 启用 Docker 官方存储库
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
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
3. 使用 apt 命令安装 Docker(社区版)
sudo apt-get update
sudo apt install docker-ce docker-ce-cli containerd.io -y
docker 包安装完成后,请将本地用户加入 docker 组,以便该用户无需 sudo 即可执行 docker 命令;注意: 将本地用户添加到 docker 组后,请确保注销并再次登录
sudo usermod -aG docker $USER
newgrp docker
验证 Docker 版本,确认 docker 守护进程服务已启动并正在运行
docker version
4. 验证 docker 守护进程服务状态,执行 systemctl 命令
sudo systemctl status docker
5. 验证和测试 Docker
docker run hello-world
6. 安装 Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/v2.17.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
7. 验证 Docker Compose
docker-compose --version