🪟
[win11] DockerとVMを使っている人の切り替えの話。
まえがき
特殊に思うんですが、ひょんなことから、WindowsでDockerとVMを割と頻繁に切り替えて使ったりします。するとどうも同時起動はできないそうで、この切り替えが地味に手間なのでそのメモです。
管理者でPowerShell(bat)する
VirtualBoxモード
switch_to_virtualbox.bat
@echo off
title 🧱 VirtualBoxモードへ切り替え
color 0E
echo =====================================================
echo 🧱 VirtualBoxモードに切り替えています...
echo =====================================================
echo.
:: Hyper-V仮想化カーネルを無効化
bcdedit /set hypervisorlaunchtype off
:: VirtualMachinePlatformを無効化
dism /online /disable-feature /featurename:VirtualMachinePlatform /norestart
dism /online /disable-feature /featurename:Windows-Hypervisor-Platform /norestart
dism /online /disable-feature /featurename:Windows-Subsystem-Linux /norestart
echo.
echo ✅ 設定完了!再起動してVirtualBoxが使えるようになります。
echo 再起動します...
timeout /t 5 /nobreak >nul
shutdown /r /t 0
Dockerモード(WSL2 / Hyper-V)
switch_to_docker.bat
@echo off
title 🐋 Dockerモードへ切り替え
color 0B
echo =====================================================
echo 🐋 Dockerモードに切り替えています...
echo =====================================================
echo.
:: Hyper-Vカーネル起動を有効化
bcdedit /set hypervisorlaunchtype auto
:: 必要なWindows機能を有効化
dism /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
dism /online /enable-feature /featurename:Windows-Hypervisor-Platform /all /norestart
dism /online /enable-feature /featurename:Windows-Subsystem-Linux /all /norestart
echo.
echo ✅ 設定完了!再起動してDockerが使えるようになります。
echo 再起動します...
timeout /t 5 /nobreak >nul
shutdown /r /t 0
これを簡素化する
毎回手打ちしてたらあれなんで、デスクトップにbatを設置します。
先ほど上記記載の「switch_to_virtualbox.bat」「switch_to_docker.bat」はファイルです。
これを右クリックで管理者として実行します。どちらでも動くと思いますが、sjisで保存した方がいいです。
Discussion