Last updated on March 19, 2024 pm
新版WSL
- 访问商店获取 Windows Subsystem for Linux
wsl --version
直接跳转到 4. 安装 Docker
过时教程害人
- 如果已经执行了第2、3步,更新后需要再执行
wsl -s docker-desktop
切换回正确的 distro
- 关闭 Hyper-V,只开启 WSL 和 虚拟化平台 两个可选功能
netsh winsock reset
然后重启
开启 Hyper-V by 壹佰
- 将下面内容复制到文本文件中,然后将文件命名为Hyper-V.bat,然后以管理员身份运行,运行完成后重启电脑(可能需要BIOS中开启处理器虚拟化支持)。
1 2 3 4 5
| 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
|
- 使用 PowerShell 启用 Hyper-V,以管理员身份打开 PowerShell 控制台,运行以下命令:
1
| Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
|
- 应用商店搜索 Ubuntu 22.04.2 LTS 并安装(可以不装)
- 开启Windows Subsystem for Linux
1
| dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
|
- 开启虚拟机特性
1
| dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
|
- 下载并安装 WSL2更新包
- 将WSL2设置成默认
1
| wsl --set-default-version 2
|
- 运行商店中安装的 Ubuntu 22.04.2 LTS (可以不装)
安装 Docker Desktop by 追逐时光者
- 下载 Docker Desktop Installer
- 换源,在系统右下角托盘图标内右键菜单选择 Settings,打开配置窗口后左侧导航菜单选择 Docker Desktop。编辑窗口内的JSON串:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| { "builder": { "features": { "buildkit": true }, "gc": { "defaultKeepStorage": "20GB", "enabled": true } }, "experimental": false, "registry-mirrors": [ "https://hub-mirror.c.163.com/", "https://docker.mirrors.ustc.edu.cn/" ] }
|
- 测试,Powershell 中运行
docker run hello-world
- Ubuntu 22.04.2 LTS 中 运行
nvidia-smi
- 右键卸载 Ubuntu 22.04.2 LTS,
wsl -l -v
保证有 docker-desktop 和 docker-desktop-data 就行
- Powershell 中运行
docker pull anibali/pytorch:2.0.0-cuda11.8-ubuntu22.04
- 启动容器并测试 cuda
1 2
| docker run -p 0.0.0.0:8001:8001 --rm -it --name torch --gpus all anibali/pytorch:2.0.0-cuda11.8-ubuntu22.04 /bin/bash python
|
1 2 3 4
| import torch print(torch.cuda.is_available()) print(torch.cuda.device_count()) print(torch.version.cuda)
|
- 测试网络访问,注意
-p 0.0.0.0
1
| docker run -p 0.0.0.0:8001:8001 --rm -it --name torch --gpus all anibali/pytorch:2.0.0-cuda11.8-ubuntu22.04 python -m http.server 8001
|
1 2 3 4 5 6 7
| mkdir data # G:\data docker run -p 0.0.0.0:8001:8001 -it --name torch --gpus all -v //g/data:/app/data anibali/pytorch:2.0.0-cuda11.8-ubuntu22.04 /bin/bash conda init # 然后退出 bash docker start torch docker exec -it torch /bin/bash conda install nano -c conda-forge nano ~/.condarc
|
jupyter
1 2 3 4 5 6
| conda create -n jupyter jupyter notebook -c conda-forge conda activate jupyter jupyter notebook --ip 0.0.0.0 --port 8001 jupyter notebook --generate-config nano ~/.jupyter/jupyter_notebook_config.py jupyter notebook # http://localhost:8001/lab?token=limour
|
1 2 3 4
| c.ServerApp.ip = '*' c.ServerApp.port = 8001 c.ExtensionApp.open_browser = False c.ServerApp.token = 'limour'
|
添加内核
1 2 3
| conda activate base conda install ipykernel -c conda-forge python -m ipykernel install --user --name pytorch
|
快速启动:docker exec -it torch /home/user/micromamba/envs/jupyter/bin/jupyter notebook
【记录】win10 通过 docker 调用 nvidia
https://hexo.limour.top/-ji-lu-win10-tong-guo-docker-diao-yong-nvidia