WSL 下的 CentOS 装 Docker

WSL 下的 CentOS 装 Docker

卸载旧版本

powershell 复制代码
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine

结果显示一堆 No Match for argument: xxx 表示我们没装过 xxx 是干净的。

安装前的准备工作

1. 安装 yum-utils

yum-utils 是一组用于管理 Yum 软件仓库和软件包的实用工具集合。

比如下面要用的 yum-config-manager 就是 yum-utils 中的一个工具。主要用于管理 Yum 软件源配置,可以添加、删除、启用或禁用软件源等操作。

powershell 复制代码
sudo yum install -y yum-utils
                                                                   
Loaded plugins: fastestmirror                                                                                           
Loading mirror speeds from cached hostfile                                                                              
Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version                                           
Nothing to do # 没啥要做的,表示我之前已经装过了

2. 添加阿里云的 yum 镜像仓库

注意:整个安装过程,只有这一步与官方不同。因为我们要用阿里的镜像仓库,其他步骤都一样。.

powershell 复制代码
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

添加前、后执行 yum repolist 对比查看,多了一个仓库

3. 快速生成 Yum 缓存

当需要频繁安装、更新软件包时,或在新安装的系统中,运行 yum makecache fast 可生成缓存以提高后续操作效率。

powershell 复制代码
yum makecache fast
  • makecache:表示创建或更新缓存
  • fast:表示快速模式。(可能会跳过一些可能比较耗时的检查,比如检查 GPG 签名等。)

安装Docker

powershell 复制代码
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

以下是对安装的这些软件包的说明:

软件包名称 说明
docker-ce Docker 引擎社区版,是 Docker 容器运行的核心组件,负责创建、运行和管理容器。
docker-ce-cli Docker 命令行工具,用于与 Docker 引擎进行交互,通过命令行执行各种 Docker 操作,如创建容器、启动容器、管理镜像等。
containerd.io 一个行业标准的容器运行时,它为 Docker 和其他容器化技术提供底层的容器运行支持,负责管理容器的生命周期、存储、网络等。
docker-buildx-plugin Docker Buildx 插件,用于构建多架构的 Docker 镜像,允许在不同的平台和架构上构建和推送容器镜像。
docker-compose-plugin Docker Compose 插件,用于定义和运行多容器的 Docker 应用程序,通过一个 YAML 文件来配置多个容器的服务、网络和存储等,简化了多容器应用的部署和管理。

启动docker

powershell 复制代码
sudo systemctl start docker

运行 hello-world

通过运行 hello-world 镜像来验证 Docker Engine 安装是否成功。

shell 复制代码
sudo docker run hello-world

如果不加 sudo 无法执行 docker 相关命令,说明当前用户可能不在 docker 组里。我们手动加一下:

docker 组是安装 docker 时自动添加的,用来管理操作 docker 的权限)

powershell 复制代码
# 查看,没有 docker 组
groups
# 将用户名 jerry 添加进 docker 组 
sudo usermod -aG docker jerry
# 刷新 docker 组
newgrp docker
# 查看,有 docker 说明就ok了
groups

显示这一堆表示成功

powershell 复制代码
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:53cc4d415d839c98be39331c948609b659ed725170ad2ca8eb36951288f81b75
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

卸载 Docker 引擎

  1. 卸载 Docker 引擎、命令行界面(CLI)、containerd 和 Docker Compose 软件包。
powershell 复制代码
sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
  1. 残留需要自己手动清理
powershell 复制代码
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

参考资料

笑虾:Wni11 下 WSL 安装 CentOS
Install Docker Engine on CentOS

相关推荐
叽里咕噜怪5 分钟前
docker-compose 编排ruoy实践
运维·docker·容器
lengjingzju24 分钟前
一网打尽Linux IPC(三):System V IPC
linux·服务器·c语言
大聪明-PLUS25 分钟前
如何编写你的第一个 Linux 内核模块
linux·嵌入式·arm·smarc
H²D41 分钟前
离线安装Dpanel面板
docker
知识分享小能手42 分钟前
Ubuntu入门学习教程,从入门到精通,Ubuntu 22.04文件压缩与解压缩知识点详解(12)
linux·学习·ubuntu
用户6135411460161 小时前
Krb5-libs-1.18.2-5.ky10.x86_64.rpm 安装失败怎么办?附详细步骤
linux
Secede.2 小时前
Windows + WSL2 + Docker + CudaToolkit:深度学习环境配置
windows·深度学习·docker
zhougl9962 小时前
Vuex 模块命名冲突:问题解析与完整解决方案
linux·服务器·apache
一世琉璃白_Y2 小时前
Ubuntu(VMware)虚拟机网络异常排查与解决方案
linux·网络·ubuntu
AI+程序员在路上3 小时前
网桥及IP转发在嵌入式linux eth0与wlan0连接使用方法
linux·tcp/ip·php