今天同事希望我帮他在某台主机中将 docker 卸载干净并进行重新安装, 其中关键在于 docker docker compose 安装时的脚本镜像

后面发现并不需要, 之前在 ubuntu 上进行安装时, 需要访问对应的 github bash 脚本, 当时的方法是使用清华的镜像进行的安装, 而 centos 直接安装并不慢, 当然得益于 centos 软件源的配置

卸载干净

小心有人也在使用 docker 保持服务运行, 遇到时先进行交涉询问, 决定是否可以停止以进行相关卸载操作

docker ps # 没有服务则进行卸载, 有则进一步沟通
cat /etc/os-release # 查看系统发布版本 这里发现是 centos
# https://docs.docker.com/engine/install/centos/
# 安装时有删除干净的相关操作
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

如果是 ubuntu 则

# https://docs.docker.com/engine/install/debian/
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
# Install using the apt repository
# https://docs.docker.com/engine/install/debian/#install-using-the-repository
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

上述在有外网的情况下比较顺利, 没有外网则用国内镜像源, 比如清华

# https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/
export DOWNLOAD_URL="https://mirrors.tuna.tsinghua.edu.cn/docker-ce"
# 如您使用 curl
curl -fsSL https://get.docker.com/ | sh
# 如您使用 wget
wget -O- https://get.docker.com/ | sh
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do apt-get remove $pkg; done
apt-get update
apt-get install ca-certificates curl gnupg
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

安装及测试

# https://docs.docker.com/engine/install/centos/#set-up-the-repository
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl start docker
sudo docker run hello-world
sudo docker compose version

参考