1. 更新系统包

sudo apt update
  1. 安装依赖包

sudo apt install apt-transport-https ca-certificates curl software-properties-common
  1. 添加 Docker 的 GPG 密钥

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  1. 添加 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
  1. 更新包索引并安装 Docker

sudo apt update
sudo apt install docker-ce
  1. 启动并设置 Docker 开机自启

sudo systemctl start docker
sudo systemctl enable docker
  1. 检查 Docker 是否安装成功

sudo docker --version
  1. (可选)将当前用户添加到 docker

sudo usermod -aG docker ${USER}

重新登录或使用如下命令重新切换到该用户验证修改

su - ${USER}