1.卸载旧版本
docker的旧版本称为docker
、docker.io
或docker engine
。如果已安装这些,请卸载它们:
sudo apt-get remove docker docker-engine docker.io containerd runc
如果apt-get报告没有安装这些软件包,那也没关系。
2.设置存储库
更新apt包索引,安装包以允许apt通过 HTTPS 使用存储库:
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
3.添加Docker官方的GPG密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
4.设置稳定存储库
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
5.更新apt包索引,安装最新版本的Docker Engine和containerd
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
6.运行hello-world 镜像验证Docker Engine是否已正确安装
sudo docker run hello-world
7.安装 docker compose
sudo apt-get update
sudo apt-get install docker-compose-plugin