docker官网
https://docs.docker.com/engine/install/ubuntu/
https://docs.docker.com/compose/install/linux/#install-using-the-repository
1.卸载旧版本
https://docs.docker.com/engine/install/ubuntu/
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
卸载 Docker Engine、CLI、containerd 和 Docker Compose 软件包:
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
主机上的映像、容器、卷或自定义配置文件不会自动删除。要删除所有映像、容器和卷:
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
2.更新apt包索引并安装包以允许apt通过 HTTPS 使用存储库:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
3.添加Docker官方GPG密钥:
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
4.设置存储库:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
5.安装 Docker 引擎
(1)更新apt包索引:
sudo apt-get update
(2)安装 Docker 引擎、containerd 和 Docker Compose。
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
(3)查看版本验证是否成功
docker --version
docker compose version
注意:
https://github.com/docker/compose/releases/download
此网址是docker-compose的github网址
6.docker阿里云镜像加速
https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxxxxxxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
再次输入docker --version
docker compose version
验证!