使用环境
Ubuntu 20.04.6 LTS (GNU/Linux 5.15.0-136-generic x86_64)
安装docker
安装依赖与配置仓库
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
添加 Docker 官方 GPG 密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
添加 Docker APT 源
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
安装 Docker Engine-Community
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
安装 Docker Compose
sudo apt-get install docker-compose-plugin
配置非 sudo 运行
sudo usermod -aG docker $USER
newgrp docker
验证安装
docker --version
# 显示 Docker Engine 版本
docker run hello-world
# 成功时会下载并运行 hello-world 镜像,打印“Hello from Docker!”等信息
