0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Hyper-V/WSL/Docker

Last updated at Posted at 2024-02-20

(自分メモ)仮想環境まわりのルーチンワーク

環境

  • Windows 11 on Windows 10 Hyper-V
  • Ubuntu 22.04 on Windows 11 WSL2

Hyper-V

ゲストWindowsの作成

  • セキュリティ > TPM : 有効化

ゲスト内での仮想化を有効にする - Nested Hyper-V

ホストWindowsターミナル[管理者] VM一覧/確認/設定
Get-Vm
Get-VMProcessor -VMName * |ft VMName,ExposeVirtualizationExtensions
Set-VMProcessor -VMName * -ExposeVirtualizationExtensions $true

WSL

Ubuntu導入

Windowsターミナル 取得可能ディストリビューション一覧/導入
wsl -l -o # 入手可能なディストリビューションを列挙
wsl --install -d Ubuntu-24.04

WSL1/WSL2の切り替え

  • 仮想環境サポートが必要(例: Nested Hyper-Vゲスト)
Windowsターミナル 導入済ディストリビューション一覧/設定
wsl -l -v
wsl --set-version <wsl-name> 2

WSLのIPをホストと共有する設定

WSL2 ver2でWSL1のようにIPをホストと共有できるようになった
また、wslファイアウォール(デフォルトで有効)をオフに

%HOME%/.wslconfig
type con > %USERPROFILE%/.wslconfig
[wsl2]
networkingMode=mirrored
firewall=false
#localhostForwarding=true
^Z RET

Hyper-VファイアウォールもOFFに

Get-NetFirewallHyperVVMCreator 
Get-NetFirewallHyperVVMSetting -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}'

# 管理者
Set-NetFirewallHyperVVMSetting -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -DefaultInboundAction Allow
wsl再起動
wsl --shutdown

Docker

導入
sudo apt install docker.io

余談 - containerd/ctr/nerdctl

containerdはDockerで使用する仮想環境レイヤ。使い勝手はdockerとあまり変わらない。

export http_proxy=http://xxxxxx:xxxx
export https_proxy=http://xxxxxx:xxxx

ctr i pull docker.io/library/ubuntu:24.04
ctr run -t --net-host --no-pivot --privileged docker.io/library/ubuntu:24.04 ubuntu
ctr t exec -t --exec-id u1 ubuntu /bin/bash
ctr c rm ubuntu
/home/をbind
export HOSTHOME=/mnt/std_log/rmmagent/kyoya
ctr run -t --net-host --no-pivot --privileged --mount type=bind,src=$HOSTHOME,dst=/home/kyoya docker.io/library/ubuntu:24.04 ubuntu

apt update && apt upgrade -y && apt install -y wget
wget https://github.com/containerd/nerdctl/releases/download/v1.7.6/nerdctl-1.7.6-linux-amd64.tar.gz
tar Cxzvvf /usr/local/bin nerdctl-1.7.6-linux-amd64.tar.gz
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?