wsl uninstall & install
wslの挙動が何かおかしくなったことからwslの入れ直しの判断。
ちゃんとアンインストールしないとインストールされないのできっちり段階を踏む。
まずはアンインストール手順
1.WindowsにインストールされているLinuxディストリビューションをすべて削除
2.wslコンポーネントの削除
3.仮想マシン プラットフォームの有効化と無効化
Windows11の設定画面からでもいいし、以下のコマンドをcmdに打つのでも良い。
仮想マシンプラットフォームの機能の無効化
dism.exe /online /disable-feature /featurename:VirtualMachinePlatform
Windows Subsystem for Linux の機能を無効化
dism.exe /online /disable-feature /featurename:Microsoft-Windows-Subsystem-Linux
WSL側で参照ができていないようなので、WSL側の登録を解除してあげれば大丈夫。
C:\Windows\system32> wslconfig /u Ubuntu-22.04
登録解除。
この操作を正しく終了しました。
この後にpowershellで
PS C:\Users\00220401950> wsl --install -d Ubuntu-22.04
Ubuntu 22.04 LTS は既にインストールされています
Ubuntu 22.04 LTS を起動しています...
==================================================================
Docker engine Install
参照にしたのは以下のURLの方。
https://zenn.dev/rhene/articles/docker-on-wsl2-without-docker-desktop
スタートメニューからUbuntuを起動とあるがwslからでもいけた。同じカーネルとやり取りしてるんだからそりゃそうか。
# Dockerのインストール
sudo apt update
curl https://get.docker.com | sh
# docker-composeのインストール
# sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# sudo chmod +x /usr/local/bin/docker-compose
sudo apt install -y docker-compose
以下のコマンドを打って、インストールが無事されているかどうか確認
sudo docker run --rm hello-world
実行結果が以下のようになれば無事完了。
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/
sudoなしでdockerコマンド実行したい
# sudo groupadd docker
sudo usermod -aG docker $USER
exit
vscode-wslのconnect to wslができなかった件
おそらくアンインストール前に残っていたキャッシュなどが悪さしたんでしょうか、vscodeがremoteでwslにつながらなくなってしまった。
いろいろ探ったところ、wslの更新をしていなかったことが原因っぽい。以下のコマンドを実行。
PowerShell 7.4.1
PS C:\Users\00220401950> wsl.exe --update
無事にvscode開く→F1→connect to wslで接続完了!!