centos7卸载重新安装docker
时间: 2024-11-13 09:21:19 浏览: 37
CentOS 7卸载并重新安装Docker的步骤如下:
1. **卸载现有Docker**:
```bash
sudo yum remove docker docker-engine docker-selinux containerd runc -y
```
如果你之前使用的是docker-compose,也需要卸载它:
```bash
sudo yum remove docker-compose -y
```
2. **删除Docker相关配置文件**:
```bash
rm -rf /var/lib/docker /etc/docker
rm -f /usr/bin/docker* /usr/lib/systemd/system/docker.service
```
3. **清除系统缓存和重启**:
```bash
sudo yum clean all
sudo systemctl daemon-reload
sudo reboot
```
4. **等待系统启动并安装基础依赖**:
启动后,再次更新系统包列表并安装基础依赖:
```bash
sudo yum update -y
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 device-mapper
```
5. **安装Docker仓库公钥**:
```bash
curl -fsSL https://download.docker.com/linux/centos/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
```
6. **添加Docker Yum仓库**:
```bash
echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/centos $(uname -m) stable' | sudo tee /etc/yum.repos.d/docker-ce.repo > /dev/null
```
7. **安装Docker**:
```bash
sudo yum install docker-ce docker-ce-cli containerd.io -y
```
8. **启动并启用Docker服务**:
```bash
sudo systemctl start docker
sudo systemctl enable docker
```
9. **验证Docker是否安装成功**:
```bash
docker run hello-world
```
阅读全文