Running Docker on WSL2 without Docker Desktop can be a bit of a pain because of its daemonized nature, especially if you're running applications inside the container on your command line instead of just letting them run in the background.
As podman doesn't require a daemon, it makes running docker containers on WSL2 much easier and cleaner and you can just alias docker=podman
as the APIs are 100% compatible. Setting up the nvidia support should be pretty straightforward as well, but as it took some time for me to figure it out (as the process isn't very well documented yet) I'm putting this Gist together for me and for everyone that might need it.
-
Run the
setup.sh
script bellow. It'll install both podman and the required nvidia packages. This script is based on the information found at https://docs.nvidia.com/cuda/wsl-user-guide/index.html and https://podman.io/getting-started/installation; -
Copy and paste or download the
oci-nvidia-hook.json
bellow and save it to the/usr/share/containers/oci/hooks.d/
. The source for this file can be found at https://github.com/NVIDIA/nvidia-container-toolkit/blob/master/oci-nvidia-hook.json -
You should be ready to go! To test if it's working just run:
podman run --rm nvidia/cuda:11.0-base nvidia-smi
and your output should look like this:
Mon Dec 27 02:18:10 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 495.53 Driver Version: 497.29 CUDA Version: 11.5 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... On | 00000000:01:00.0 On | N/A |
| 0% 47C P0 23W / 100W | 1781MiB / 4096MiB | N/A Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+