当我的应用程序在主机上的另一个Docker容器中运行时,如何使用DevContainer在VSCODE中使用断点?

发布于 2025-02-08 06:50:44 字数 2036 浏览 1 评论 0原文

因此,我有一个在VSCODE中运行的DevContainer,这是我的开发人员。它具有正确的节点等版本。因此,所有开发人员都使用相同版本的节点,npm等。

然后,我们运行docker-compose以启动我们的应用程序和数据库。该应用程序服务具有到本地目录的卷映射,因此它可以拾取从内部VSCODE进行的代码更改 - 到目前为止还不错。

但是,我现在如何允许VSCODE连接到应用程序的运行实例并停止断点?

这是一个打字稿Nestjs应用。 看起来好像是在听:

exchange-be-uiapi    | Debugger listening on ws://127.0.0.1:9229/d68b4dad-6449-4380-9685-b9afb97b3a4a
exchange-be-uiapi    | For help, see: https://nodejs.org/en/docs/inspector

这是我的启动。

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
      {
        "type": "node",
        "request": "attach",
        "name": "Attach Exchange BE",
        "port": 9229,
        "restart": true
      }
    ]
  }

我们从nest start -debug -watch开始它, ,我找不到我能找到的输出,所以我不知道问题是什么。

App Docker-compose.yaml看起来像这样:

version: '3.8'
services:
  exchange-db:
    image: postgres:13.6
    environment:
      POSTGRES_USER: exchange-db
      POSTGRES_PASSWORD: exchange-db
      POSTGRES_DB: exchange-db
    volumes:
      - ./postgresdata:/var/lib/postgresql/data
    container_name: exchange-db
    networks:
      - exchange-be-network
    ports:
      - 5432:5432

  exchange-be-uiapi:
    container_name: exchange-be-uiapi
    env_file: ./.env
    environment:
      THALLO_START_MODE: uiapi
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - exchange-db
    ports:
      - 3001:3001
      - 9229:9229
    volumes:
      - ./:/opt/thallo/exchange-be
    networks:
      - exchange-be-network  
# volumes:
  # exchange-be-volume:
  #   external: true
  # postgresdata:

networks:
  exchange-be-network:
    external: true

谢谢!

So I have a devcontainer running in vscode, which is my dev env. It has the correct version of node etc.. so all devs are using the same version of node, npm etc..

We then run docker-compose up to start our app and a database. The app service has a volume map to the local directory so it picks up code changes made from inside vscode - so far so good.

But how do I now allow vscode to connect to that running instance of the app and stop on breakpoints?

This is a typescript nestjs app. We start it with nest start --debug --watch and it looks like it's listening:

exchange-be-uiapi    | Debugger listening on ws://127.0.0.1:9229/d68b4dad-6449-4380-9685-b9afb97b3a4a
exchange-be-uiapi    | For help, see: https://nodejs.org/en/docs/inspector

And this is my launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
      {
        "type": "node",
        "request": "attach",
        "name": "Attach Exchange BE",
        "port": 9229,
        "restart": true
      }
    ]
  }

But when I start the debugger the progress bar starts for a few seconds then stops, there's no output that I can find so I don't know what the issue is.

The app docker-compose.yaml looks like this:

version: '3.8'
services:
  exchange-db:
    image: postgres:13.6
    environment:
      POSTGRES_USER: exchange-db
      POSTGRES_PASSWORD: exchange-db
      POSTGRES_DB: exchange-db
    volumes:
      - ./postgresdata:/var/lib/postgresql/data
    container_name: exchange-db
    networks:
      - exchange-be-network
    ports:
      - 5432:5432

  exchange-be-uiapi:
    container_name: exchange-be-uiapi
    env_file: ./.env
    environment:
      THALLO_START_MODE: uiapi
    build:
      context: .
      dockerfile: Dockerfile
    depends_on:
      - exchange-db
    ports:
      - 3001:3001
      - 9229:9229
    volumes:
      - ./:/opt/thallo/exchange-be
    networks:
      - exchange-be-network  
# volumes:
  # exchange-be-volume:
  #   external: true
  # postgresdata:

networks:
  exchange-be-network:
    external: true

Thanks!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文