【问题标题】:Run an NGC Container in VS Code on Ubuntu在 Ubuntu 上的 VS Code 中运行 NGC 容器
【发布时间】:2019-09-14 03:13:28
【问题描述】:

我需要在 Ubuntu 的 Docker 上的 NVIDA GPU Cloud (NGC) container 中运行 Python 脚本,并且我想使用 Visual Studio Code 来编辑、运行和调试它。我已经安装了VS Code Docker Extension 并阅读了文档,但似乎都不符合我的目的。

我已关注NGC docs,为 Docker (nvidia-docker2) 安装了 NVIDIA Container Runtime,现在我将在命令行上启动 NGC 容器压缩包

docker load -i  foo.tar
sudo docker run {...}

如何配置 VS Code 以便可以在此容器中运行和调试 Python 脚本?

【问题讨论】:

  • 好问题,我将尝试创建一个显示示例的 repo,但问题是如何: 1. 配置 Dockerfile 以在调试模式下运行脚本 2. 将 VS Code 调试器与容器连接一次跑步。我将制作第二个 Dockerfile,它仅在调试模式下运行脚本,在调试模式下,我将配置为使用 --network host 运行容器(docker-compose 会更好但更复杂),并记得在之前构建两个图像调试以确保您运行的是最新的
  • 这个只是使用Python扩展github.com/DonJayamanne/vscode-python-samples/tree/master/…(免责声明:我没有尝试过,但看起来它有正确的想法)

标签: docker visual-studio-code nvidia ptvs nvidia-docker


【解决方案1】:

下载NVIDA GPU Cloud (NGC) container

使用VS Code Docker ExtensionVisual Studio Code 中创建/home/bob/foobar.py

import ptvsd
import time
ptvsd.enable_attach(address = ('0.0.0.0', 5678))
ptvsd.wait_for_attach()
time.sleep(2)
print("all righty then")

在最后一行设置断点。

调试|添加配置

Docker:附加到节点

launch.json 中添加到“配置”

{
   "name": "Python Attach (Remote Debug ptsvd default)",
   "type": "python",
   "request": "attach",
   "pathMappings": [
       {
          "localRoot": "/home/bob", // You may also manually specify the directory containing your source code.
          "remoteRoot": "/home/bob" // Linux example; adjust as necessary for your OS and situation.
       }
    ],
            "port": 5678, // Set to the remote port.
            "host": "0.0.0.0" // Set to your remote host's public IP address.
},

打开终端窗口:

$ docker load -i foo.tar
$ docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
nvidia/cuda           9.0-base            9dcd7cd95db6        2 weeks ago         135MB
nvcr.io/nvidia/cuda   latest              506c995952d1        7 weeks ago         2.74GB    

$ docker run -p 5678:5678 latest    

root@deadbeef: python -m pip install --user --upgrade ptvsd
root@deadbeef: python foobar.py 

使用配置“Python Attach (Remote Debug ptsvd default)”启动调试器。它在断点处停止。

【讨论】:

    猜你喜欢
    • 2015-07-10
    • 2017-01-10
    • 1970-01-01
    • 2021-02-10
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2018-03-10
    • 1970-01-01
    相关资源
    最近更新 更多