windows安装docker

环境准备

启用Hyper-V

打开windows功能,找到Hyper-V并勾选,
在这里插入图片描述

  • 如果找不到Hyper-V
    新建txt,然后编辑内容
pushd "%~dp0"
dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt
for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"
del hyper-v.txt
Dism /online /enable-feature /featurename:Microsoft-Hyper-V -All /LimitAccess /ALL
pause

保存内容后,重命名txt为bat,然后以管理员身份运行。执行结果如下
在这里插入图片描述
选择重启,然后勾选Hyper-V保存
在这里插入图片描述

启用虚拟化

默认是开启的
在这里插入图片描述

安装WSL

dism.exe /Online /Enable-Feature /FeatureName:VirtualMachinePlatform /All
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

命令解析

这些命令是用于在Windows操作系统中启用某些功能的命令。具体来说,它们使用了dism.exe(Deployment Image Servicing and Management)工具来启用特定的功能。以下是每个命令的解析:

  1. dism.exe /Online /Enable-Feature /FeatureName:VirtualMachinePlatform /All
    这个命令用于启用Windows中的虚拟化平台功能。/Online参数表示在不重启计算机的情况下执行操作,/Enable-Feature表示要启用的功能,/FeatureName:VirtualMachinePlatform指定要启用的功能名称,/All表示在所有可用的Windows版本上启用该功能。
  2. dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
    这个命令用于启用Windows中的Linux子系统功能。同样,/Online表示在线操作,/Enable-Feature表示启用功能,/FeatureName:Microsoft-Windows-Subsystem-Linux指定要启用的功能名称,/All表示在所有可用的Windows版本上启用该功能,/NoRestart表示在完成操作后不重启计算机。
  3. dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    这个命令与第一个命令相同,再次启用虚拟化平台功能,但不重启计算机。

不用的时候可以关闭

dism.exe /Online /Disable-Feature /FeatureName:VirtualMachinePlatform /All
  • 列出可安装版本
wsl.exe --list --online
  • 出现报错,无法解析服务器的名称或地址
    在这里插入图片描述
    解决:
    访问https://www.sojson.com/ip/25OoO!!qBVnMl05wz052BJjxzZvNy1HgDPDMl3fMC.html
    在这里插入图片描述
    标注1的位置输入raw.githubusercontent.com,点击标注2,查询到的结果标注3位置,拿到ip,然后编辑hosts文件,将刚查到的信息加入到hosts文件保存。
    在这里插入图片描述
  • 再次执行安装查看可安装的版本列表,正常显示
wsl.exe --list --online

在这里插入图片描述

  • 安装
    记得加-d,网上都没写要-d参数
wsl.exe --install OracleLinux_8_7

在这里插入图片描述

wsl切换root账户

  • 默认 root 密码是随机的,即每次开机都有一个新的 root 密码。执行sudo passwd,
  • 输入当前用户的密码,终端会提示我们输入新的密码并确认,此时的密码就是 root 新密码。
  • su root切换到root用户,输入刚才的密码即可

无法使用systemctl

通过wsl使用linux,默认情况下系统使用的是 SysV 而不是 systemd,并且报错信息如下

[root@lenovo src]# systemctl
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
  • 查看第一进程
ps -p 1 -o comm=

在这里插入图片描述
这就没有办法使用systemctl。可以使用sysvinit 命令,代替 systemctl 命令。但是出现如下问题。
在这里插入图片描述

  • 配置开启systemctl
    进入虚拟机,执行vim /etc/wsl.conf,wsl.conf可能不存在,直接执行就行,新增一个。
    编辑保存内容
[boot]
systemd=true

使用 PowerShell 中的 wsl.exe --shutdown 命令重启所有 WSL 实例。重启后,systemd 将会运行。

安装docker

下载地址:https://mirrors.aliyun.com/docker-toolbox/windows/docker-for-windows/
在这里插入图片描述
下载好进行安装,安装完成
在这里插入图片描述

配置docker

打开刚才安装好的docker,第一次需要同意,
在这里插入图片描述

配置国内镜像

在这里插入图片描述
添加https://pi9dpp60.mirror.aliyuncs.com,要带引号
在这里插入图片描述

使用

直接打开cmd窗口,执行docker命令即可,查个mysql看看
在这里插入图片描述
docker的使用:https://blog.csdn.net/a3562323/article/details/104222229

拉取失败

拉取nacos失败,换个rabbitmq试试,还是失败
在这里插入图片描述

  • 解决拉取失败,
    多加几个镜像
"registry-mirrors": [
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://registry.docker-cn.com",
    "http://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn",
    "https://docker.mirrors.ustc.edu.cn"
  ]

或者

  "registry-mirrors": [
    "https://docker.m.daocloud.io",
    "https://dockerhub.icu",
    "https://registry.aliyuncs.com",
    "https://docker.nju.edu.cn"
  ]

  • 拉取成功
    在这里插入图片描述
  • 12
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值