見出し画像

【44日目】WSL2とDocker環境を整えました

2024/12/28スタートで今日は2025/02/09。44日目です。

Docker環境を整えました。

こちらを参考にしました。


WSL

管理者権限で実行したらこんなメッセージ。アップデートが必要のようです。

C:\Windows\System32>wsl -l -v
続行するには、Linux 用 Windows サブシステムを最新バージョンに更新する必要があります。'wsl.exe --update' を実行して更新できます。
詳細については、 https://aka.ms/wslinstall
 を参照してください
任意のキーを押して Linux 用 Windows サブシステムをインストールします。
キャンセルするには、Ctrl + C キーを押すか、このウィンドウを閉じます。
このプロンプトは 60 秒後にタイムアウトします。


ダウンロード中: LinuxWindows サブシステム 2.4.10
インストール中: LinuxWindows サブシステム 2.4.10
LinuxWindows サブシステム 2.4.10 はインストールされました。
この操作を正しく終了しました。
  NAME      STATE           VERSION
* Ubuntu    Stopped         1

WSL1の残骸。無駄に苦労した日々を思い出しました。

自宅PCと持ち歩きNoteでWSLのバージョンが違っていることに気が付かず、外で書いたコードが家のPC動かないというドツボにハマっていました。

WinのHDD上にあるchromedriver.exeへのアクセスが、WSL1上のpyでは成功するがWSL2上のpyではアクセスできない、そんな感じだったと思います。

深追いすると解決しそうですが、先人がすごく悩んでいる記事があって、それを読んで、きっぱりあきらめました。POSIXシェルを使いたいだけなので、GitBashで代用すればいいやと。Win内でPyが動けば問題ないですし。

シティヘブンの0時予約争奪戦のために書いたPy+Seleniumが動けばいいので無理してWSL Ubuntuで動作させる必要もなかったし・・・。

結局、ネット予約は姫予約に勝てないと知り、実働2ヶ月のコードでした。「0時争奪戦で毎回口開けに予約成功している私のことを、スタッフさんは不思議がっていた」とキャストさんから聞いたのも、いい思い出。

話逸れましたが、何も考えず install したら怒られましたので、別名でやりなおします。

:\Windows\System32>wsl --install
ダウンロード中: Ubuntu
[==========================56.4%=                          ]



C:\Windows\System32>wsl --install
ダウンロード中: Ubuntu
インストール中: Ubuntu
w指定された名前のディストリビューションは既に存在します。--name を使用して別の名前を選択してください。
エラー コード: Wsl/InstallDistro/Service/RegisterDistro/ERROR_ALREADY_EXISTS



C:\Windows\System32>wsl --install
ダウンロード中: Ubuntu
^C                          0.7%                           ]



C:\Windows\System32>wsl --install --name Ubuntu_20250209
ダウンロード中: Ubuntu
インストール中: Ubuntu
ディストリビューションが正常にインストールされました。'wsl.exe -d Ubuntu_20250209' を使用して起動できます

C:\Windows\System32>wsl -l -v
  NAME               STATE           VERSION
* Ubuntu             Stopped         1
  Ubuntu_20250209    Stopped         2

動きました。

C:\Windows\System32>wsl -d Ubuntu_20250209
Provisioning the new WSL instance Ubuntu_20250209
This might take a while...
Create a default Unix user account: ftad
New password:
Retype new password:
passwd: password updated successfully
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 24.04.1 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

 System information as of Sun Feb  9 12:45:45 JST 2025

  System load:  0.04                Processes:             31
  Usage of /:   0.1% of 1006.85GB   Users logged in:       0
  Memory usage: 5%                  IPv4 address for eth0: 172.21.140.238
  Swap usage:   0%

This message is shown once a day. To disable it please create the
/home/ftad/.hushlogin file.


デフォルトを変更しました。

C:\Windows\System32>wsl -l -v
  NAME               STATE           VERSION
* Ubuntu             Stopped         1
  Ubuntu_20250209    Running         2

C:\Windows\System32>wsl --set-default Ubuntu_20250209
この操作を正しく終了しました。

C:\Windows\System32>wsl -l -v
  NAME               STATE           VERSION
* Ubuntu_20250209    Running         2
  Ubuntu             Stopped         1

wslコマンドで、Ver2側のUbuntuが動作するようになりました。


C:\Windows\System32>wsl
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ftad:/mnt/c/Windows/System32$ exit


Docker Desktop

ここからWindows用をダウンロードします。



Docker起動


「許可」を選択。スクショ取れないのでスマホのカメラで。



C:\Windows\System32>docker run -d -p 80:80 docker/getting-started
Unable to find image 'docker/getting-started:latest' locally
latest: Pulling from docker/getting-started
4f7e34c2de10: Download complete
c158987b0551: Download complete
9b6f639ec6ea: Download complete
33e0cbbb4673: Download complete
1e35f6679fab: Download complete
f1d1c9928c82: Download complete
cb9626c74200: Download complete
ee68d3549ec8: Download complete
b6334b6ace34: Download complete
Digest: sha256:d79336f4812b6547a53e735480dde67f8f8f7071b414fbd9297609ffb989abc1
Status: Downloaded newer image for docker/getting-started:latest
b15e1fa914085828117153456ed0aa3d11e8e825569b990c42d9ee5ae3b5d10d

起動しました。



WSLとして、docker-desktopが動作?混乱しています・・・。

つづく。

いいなと思ったら応援しよう!