Cài Đặt WSL2 trên windows 10, không nên xài docker desktop mà nên cài thẳng lên ubuntu
Không nên cài Docker Desktop vì:
- Không stable, lỗi quá nhiều với wsl2, crash tùm lum
- WSL tự thay đổi quá nhiều thứ behind the scence để thích ứng với docker desktop như networking, firewall, dns , ...
Hướng cài:
Đòi hỏi sẽ phải cần Mở Windows Features on:
- Hyper-V
- .NET 4.8
- Virtual Machine Platform
- Windows Subsystem for Linux
- Cài WSL2 bình thường với ubuntu latest
List Linux Distro Available:
wsl.exe -l -o
Install Version
wsl.exe --install -d Ubuntu-24.04
Config WSL sửa lỗi WSL2 theo bài cũ: https://wiki.kyluat.com/books/programming/page/windows-wsl-ubuntu-docker-node-nestjs-app-khong-vao-duoc
Cấu hình wsl nâng ram và cpus trên windows
tạo file .wslconfig theo path: c:/users/hothanhson/.wslconfig
[wsl2]
# Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory=32GB
# Sets the VM to use two virtual processors
processors=8
kernelCommandLine = cgroup_no_v1=all
[experimental]
autoMemoryReclaim=true
auto memory reclaim để wsl nó reset lại memory khi bị leak
/etc/resolv.conf
sudo chattr -i /etc/resolv.conf
sudo vi /etc/resolv.conf
nameserver 192.168.1.11
nameserver 172.21.240.1
sudo chattr +i /etc/resolv.conf
/etc/wsl.conf
[boot]
systemd=true
[network]
generateResolvConf = false
generateHosts = true
networkingMode=NAT
Config user sao cho không có cần đánh sudo và password nhiều
sudo su -
sudo visudo
Thêm
- son ALL=(ALL:ALL) ALL
- son ALL=(ALL) NOPASSWD:ALL
- son là username của ubuntu
Cài đặt docker trên ubuntu
https://docs.docker.com/engine/install/ubuntu/
Cài đặt docker dns ở /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=cgroupfs"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"dns": ["192.168.1.11", "8.8.8.8"],
"iptables": false
}
Cài đặt GPU lên ubuntu
https://github.com/ashishpatel26/Cuda-installation-on-WSL2-Ubuntu-20.04-and-Windows11?tab=readme-ov-file
Xem coi mình đang xài GPU gì:
nhấn WIN+R đánh dxdiag để check mình đang xài graphic card gì
WIN+R
dxdiag
cài đặt nvdia toolkit cho docker:
sudo nano /etc/apt/sources.list
Thêm vào dòng này để có repo cài libt5info missing:
deb http://archive.ubuntu.com/ubuntu/ lunar universe
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sed -i -e '/experimental/ s/^#//g' /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
cài libsecret
sudo apt install libsecret-1-0
cài gnome keyring:
sudo apt install gnome-keyring
Add user vào docker group để khỏi hỏi Sudo hoài:
sudo usermod -aG docker $USER
Thêm quyền cho user son:
sudo usermod -aG sudo son
Kết quả:
Test Ubuntu với GPU:
nvidia-smi
Test Docker với gpu:
docker run --gpus all nvcr.io/nvidia/k8s/cuda-sample:nbody nbody -gpu -benchmark
Docker Compose Template với GPU:
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]