Limour

Limour

临床医学在读。

[Record] Using Docker to Invoke Nvidia on Win10

New WSL#

  1. Visit the store to get Windows Subsystem for Linux
  2. Use wsl --version to directly jump to step 4: Install Docker
  3. Outdated tutorials are harmful
  4. If you have already completed steps 2 and 3, after the update, you need to execute wsl -s docker-desktop again to switch back to the correct distro. Switch back to the correct distro
  5. Disable Hyper-V and only enable WSL and Virtualization Platform as optional features
  6. Run netsh winsock reset and then restart the computer

Enable Hyper-V by Yi Bai#

  1. Copy the following content to a text file, then name the file Hyper-V.bat, and run it as an administrator. After running, restart the computer (you may need to enable processor virtualization support in the BIOS).
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
  1. Enable Hyper-V using PowerShell. Open PowerShell console as an administrator and run the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

Install WSL2 by Ali7&MS#

  1. Search for Ubuntu 22.04.2 LTS in the Microsoft Store and install it (optional)
  2. Enable Windows Subsystem for Linux
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  1. Enable Virtual Machine Platform
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  1. Download and install the WSL2 update package
  2. Set WSL2 as the default version
wsl --set-default-version 2
  1. Run the installed Ubuntu 22.04.2 LTS from the store (optional)

Install Docker Desktop by Time Chaser#

  1. Download Docker Desktop Installer
  2. Change the source. Right-click on the Docker Desktop icon in the system tray and select Settings. In the opened configuration window, select Docker Desktop from the left navigation menu. Edit the JSON string in the editing window:
{
  "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/"
  ]
}
  1. Test by running docker run hello-world in PowerShell

Use Nvidia by Unknown&bpq#

  1. Run nvidia-smi in Ubuntu 22.04.2 LTS
    image
  2. Uninstall Ubuntu 22.04.2 LTS, make sure you have docker-desktop and docker-desktop-data by running wsl -l -v
  3. Run docker pull anibali/pytorch:2.0.0-cuda11.8-ubuntu22.04 in PowerShell
  4. Start the container and test cuda
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
import torch # Import if PyTorch is successfully installed
print(torch.cuda.is_available()) # Check if CUDA is available
print(torch.cuda.device_count()) # Check the number of available CUDA devices
print(torch.version.cuda) # Check the version of CUDA
  1. Test network access, pay attention to -p 0.0.0.0
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

Conda by bpq&LATLAJ#

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 # Then exit bash
docker start torch
docker exec -it torch /bin/bash
conda install nano -c conda-forge
nano ~/.condarc

Jupyter#

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
c.ServerApp.ip = '*'
c.ServerApp.port = 8001
c.ExtensionApp.open_browser = False
c.ServerApp.token = 'limour'

Add kernel#

conda activate base
conda install ipykernel -c conda-forge
python -m ipykernel install --user --name pytorch

image
Quick start: docker exec -it torch /home/user/micromamba/envs/jupyter/bin/jupyter notebook

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.