簡體   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 .

測試用例工作:

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])))"

我應該怎么做才能使用 Visual Studio Code 編寫的程序在 docker 而不是 python(本地安裝)中運行?

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

它不起作用,因為我理解這是 docker 中的路徑,而不是主機上的路徑。 我應該用里面的程序構建一個新的 docker 映像嗎? 我想使用下載的圖像而不更改它。

您必須在 docker 上掛載您的本地目錄[視覺代碼保存了您的 python 文件的位置]。 這是一個工作示例 -

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

我嘗試過的工作示例-

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

要讓您的程序在 docker 上運行,您有很多選擇:

  1. 在您的 Dockerfile 中復制 docker 中的代碼

  2. 您可以將包含 python 代碼的文件夾安裝為 docker 卷 [推薦]

有關更多信息,請查看媒體文章

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM