[英]Nvidia-Docker API for Python?
I am currently running a lot of similar Docker containers which are created and run by a Python script via the official API.我目前正在运行许多类似的 Docker 容器,这些容器是通过官方 API 由 Python 脚本创建和运行的。 Since Docker natively doesn't support GPU mapping, I tested Nvidia-Docker, which fulfills my requirements, but I'm not sure how to integrate it seamlessly in my script.
由于 Docker 本身不支持 GPU 映射,我测试了 Nvidia-Docker,它满足我的要求,但我不确定如何将它无缝集成到我的脚本中。
I tried to find the proper API calls for Nvidia-Docker using Google and the docs, but I didn't manage to find anything useful.我试图使用 Google 和文档为 Nvidia-Docker 找到正确的 API 调用,但我没有找到任何有用的东西。
My current code looks something like this:我当前的代码如下所示:
# assemble a new container using the params obtained earlier
container_id = client.create_container(img_id, command=commands, stdin_open=True, tty=True, volumes=[folder], host_config=client.create_host_config(binds=[mountpoint,]),detach=False)
# run it
client.start(container_id)
The documentation for the API can be found here.可以在此处找到 API 的文档。
From Nvidia-Dockers Github page:来自Nvidia-Dockers Github页面:
The default runtime used by the Docker® Engine is runc, our runtime can become the default one by configuring the docker daemon with --default-runtime=nvidia.
Docker® 引擎使用的默认运行时是 runc,我们的运行时可以通过使用 --default-runtime=nvidia 配置 docker 守护进程来成为默认运行时。 Doing so will remove the need to add the --runtime=nvidia argument to docker run.
这样做将消除将 --runtime=nvidia 参数添加到 docker run 的需要。 It is also the only way to have GPU access during docker build.
这也是在 docker build 期间访问 GPU 的唯一方法。
Basically, I want to add the --runtime=nvidia-docker argument to my create_container call, but there is no support for that as it seems.基本上,我想将 --runtime=nvidia-docker 参数添加到我的 create_container 调用中,但似乎不支持。
But since I need to switch between runtimes multiple times during the script execution (mixing Nvidia-Docker and native Docker containers) the quick and dirty way would be to run a bash command using subprocess but I feel like there has to be a better way.但是由于我需要在脚本执行期间多次在运行时之间切换(混合 Nvidia-Docker 和本机 Docker 容器),快速而肮脏的方法是使用子进程运行 bash 命令,但我觉得必须有更好的方法。
TL;DR: I am looking for a way to run Nvidia-Docker containers from a Python script. TL;DR:我正在寻找一种从 Python 脚本运行 Nvidia-Docker 容器的方法。
run()
and create()
methods have runtime
parameter according to https://docker-py.readthedocs.io/en/stable/containers.html run()
和create()
方法根据https://docker-py.readthedocs.io/en/stable/containers.html具有runtime
参数
Which has sense because docker
cli tool is pretty simple and every command translate in a call to the docker engine service REST API这是有道理的,因为
docker
cli 工具非常简单,每个命令都在调用 docker 引擎服务 REST API 时进行转换
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.