docker with GPU support
自己总结的:
nvidia-docker, 不支持windows,
2019.10, nvidia-docker过时了,从docker 1903开始,安装一个nvidia-container-runtime就行了, --gpus
2020.12, docker 好像可以直接在wsl2里面跑了, 需要windows inside版本
win 10 2021版本直接包含了对GPU的支持,不再需要inside版本
copy from SO:
2021 updated answer
If you need to access NVIDIA CUDA from a Linux container on Windows 10, there is an easy way to do so, if you are fine with the (current) requirement of being on an Insider build. I was successful with training models on GPU in TensorFlow 2 using this method.
- Update Windows 10 to build 20149 or higher. At the time of writing, only Insider Dev branch will work -- you can check the build numbers on the Windows Insider webpage.
- Install the NVIDIA CUDA WSL driver (free registration is required)
- Install Docker Desktop
- It will guide you through enabling WSL2 if you haven't already.
- If you already have it installed, update it to the latest version and enable
Settings - General - Use the WSL2 backed engine
. - To be able to use the
docker
CLI from inside WSL2 (not just from PowerShell/cmd), enable the integration inSettings - Resources - WSL INTEGRATION
.
- Test using the command
docker run --rm -it --gpus=all nvcr.io/nvidia/k8s/cuda-sample:nbody
You need to pass --gpus=all
to docker run
to enable the container to access GPU. (If you use VSCode Remote Containers, add "runArgs": ["--gpus=all"],
to devcontainer.json
.)
You may come across mentions of --runtime=nvidia
in descriptions of images meant for nvidia-docker
(like the official TensorFlow images). Simply replace --runtime=nvidia
by --gpus=all
in the provided commands.
Ref:
https://stackoverflow.com/questions/49589229/is-gpu-pass-through-possible-with-docker-for-windows (https://www.docker.com/blog/wsl-2-gpu-support-is-here/)
https://stackoverflow.com/questions/25185405/using-gpu-from-a-docker-container
Is GPU pass-through possible with docker for Windows?