简体   繁体   English

在 nvidia cuda docker 中运行 python 脚本

[英]Running python script in nvidia cuda docker

I downloaded and set up the docker https://www.tensorflow.org/install/docker and the image https://github.com/NVIDIA/nvidia-docker . I downloaded and set up the docker https://www.tensorflow.org/install/docker and the image https://github.com/NVIDIA/nvidia-docker .

Test case works:测试用例工作:

docker run --gpus all -it --rm tensorflow / tensorflow: latest-gpu \
python -c "import tensorflow as tf; print (tf.reduce_sum (tf.random.normal ([1000, 1000])))"

What should I do to make the program written in Visual Studio Code run in docker instead of python (locally installed)?我应该怎么做才能使用 Visual Studio Code 编写的程序在 docker 而不是 python(本地安装)中运行?

docker run --gpus all -it --rm tensorflow / tensorflow: latest-gpu \
    python /home/something.py

It doesn't work because what I understand this is the path in the docker and not on the host machine.它不起作用,因为我理解这是 docker 中的路径,而不是主机上的路径。 Should I build a new docker image with the program inside?我应该用里面的程序构建一个新的 docker 映像吗? I wanted to use the downloaded image without changing it.我想使用下载的图像而不更改它。

You will have to mount your local directory [where visual code has saved your python file] on docker.您必须在 docker 上挂载您的本地目录[视觉代码保存了您的 python 文件的位置]。 Here is a working example -这是一个工作示例 -

docker run --gpus all -v <your_directory_where_visual_code_has_saved_python_file>:/home -it --rm tensorflow/tensorflow:latest-gpu docker 运行 --gpus all -v <your_directory_where_visual_code_has_saved_python_file>:/home -it --rm tensorflow/tensorflow:latest-gpu
python /home/something.py python /home/something.py

My working example that i tried -我尝试过的工作示例-

docker run --gpus all -v /home/ubuntu/test:/home/test -it tensorflow/tensorflow:latest-gpu python /home/jitest.py

To make your program run on docker, you have many options:要让您的程序在 docker 上运行,您有很多选择:

  1. in your Dockerfile copy the code inside the docker在您的 Dockerfile 中复制 docker 中的代码

  2. you can mount the folder containing your python code as docker volume [recommended]您可以将包含 python 代码的文件夹安装为 docker 卷 [推荐]

for more information check this medium articles有关更多信息,请查看媒体文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM