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

相关推荐
我是谁??4 分钟前
CentOS 7.9安装GCC 7.3.0
linux·运维·centos
RunningOnMyWay6 分钟前
CentOS 7 安装yum使用报错:Cannot find a valid baseurl for repo: base/7/x86_6
linux·运维·服务器·centos
Just_Paranoid10 分钟前
828华为云征文|部署在线文件管理器 Spacedrive
docker·华为云·文件管理·flexus云服务器·spacedrive
玖石书26 分钟前
Docker 容器网络技术
运维·docker·容器
付宇轩1 小时前
进程的重要函数
linux·数据库
芊言芊语2 小时前
CentOS详细解析及其配置方法
linux
杨~friendship2 小时前
Ubuntu上使用qt和opencv显示图像
linux·开发语言·c++·qt·opencv·ubuntu
laizhenghua2 小时前
Linux定时启动jar应用shell脚本分享
linux
Flying_Fish_roe2 小时前
linux-安全管理-SSH 安全管理
linux·安全·ssh
ZH_qaq3 小时前
Linux 常用指令
linux·运维·服务器