如何使用 Docker SDK for Python 运行具有特定 GPU 的 Docker 容器

发布于 2025-01-13 02:10:10 字数 193 浏览 2 评论 0原文

在命令行中,我习惯使用 --gpus 参数运行/创建具有特定 GPU 的容器:

docker run -it --gpus '"device=0,2"' ubuntu nvidia-smi

Docker SDK for Python 文档不是很有帮助,而且我找不到关于如何使用 python SDK 执行相同操作的良好解释。有办法做到吗?

In the command line I am used to run/create containers with specific GPUs using the --gpus argument:

docker run -it --gpus '"device=0,2"' ubuntu nvidia-smi

The Docker SDK for Python documentation was not very helpful and I could not find a good explanation on how to do the same with the python SDK. Is there a way to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毁梦 2025-01-20 02:10:10

这是使用 Docker SDK for Python 运行/创建具有特定 GPU 的 docker 容器的方法:

client.containers.run('ubuntu',
                          "nvidia-smi",
                           device_requests=[
                           docker.types.DeviceRequest(device_ids=['0','2'], capabilities=[['gpu']])]) 

这样您还可以使用此处指定的其他 GPU 资源选项:
https://docs.docker.com/config/containers/resource_constraints/

This is how you can run/create docker containers with specific GPUs using the Docker SDK for Python:

client.containers.run('ubuntu',
                          "nvidia-smi",
                           device_requests=[
                           docker.types.DeviceRequest(device_ids=['0','2'], capabilities=[['gpu']])]) 

This way you can also use other GPU resource options specified here:
https://docs.docker.com/config/containers/resource_constraints/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文