You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让VS Code调试在Docker Compose与Node.js环境中正常工作?

Docker Compose + VS Code调试断点无法触发问题

我一直在按照微软的Docker Compose调试指南在VS Code中操作,所有步骤都已完成,但Docker Compose配置下的VS Code调试始终无法正常工作。Docker Compose能正常启动,附加到容器后却完全触发不了任何断点。不过launch.json里配置的TypeScript调试是正常的,能触发断点也能查看日志,所以问题肯定出在我的配置上。会不会因为使用了TypeScript,得在生成的JS文件而非原TypeScript文件中设置断点?

以下是我的配置文件,求帮忙排查:

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": [
        {
            "name": "Docker: Attach to Node",
            "type": "node",
            "request": "attach",
            "preLaunchTask": "Compose Up (Dev)",
            "postDebugTask": "Compose Down",
            "localRoot": "{workspaceFolder}",
            "remoteRoot": "/usr/src/app"
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Debug Typescript",
            "skipFiles": ["<node_internals>/**"],
            "program": "${workspaceFolder}/dist/bot.js",
            "preLaunchTask": "tsc: build - src/tsconfig.json",
            "envFile": "${workspaceFolder}/src/.env.development.local",
            "outFiles": ["${workspaceFolder}/**/*.js"],
            "resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**"],
            "console": "internalConsole"
        },
    ]
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compose Up (Dev)",
            "type": "docker-compose",
            "dockerCompose": {
                "up": {
                    "detached": true,
                    "build": true,
                    "profiles": [
                        "dev"
                    ]
                },
                "envFile": "${workspaceFolder}/src/.env.development",
                "files": [
                    "${workspaceFolder}/docker-compose.yml"
                ]
            }
        },
        {
            "label": "Compose Down",
            "type": "docker-compose",
            "dockerCompose": {
                "down": {
                    "removeVolumes": true,
                    "removeImages": "all"
                }
            }
        }
    ]
}

docker-compose.yml

services:
    prisma-studio:
        container_name: prisma-studio
        image: timothyjmiller/prisma-studio:latest
        restart: unless-stopped
        depends_on:
            postgres:
                condition: service_healthy
        profiles:
            - dev
        environment:
            POSTGRES_URL: ${DATABASE_URL}
        ports:
            - ${PRISMA_STUDIO_PORT}:${PRISMA_STUDIO_PORT}
    postgres:
        image: postgres:12.14
        container_name: postgres
        hostname: postgres
        environment:
            POSTGRES_USER: ${DB_USER}
            POSTGRES_PASSWORD: ${DB_USER_PASS}
            POSTGRES_DB: ${DB_NAME}
        ports:
            - ${DB_PORT}:${DB_PORT}
        restart: 'unless-stopped'
        volumes:
            - 'postgres-data:/var/lib/postgresql/data'
        healthcheck:
            test: ["CMD-SHELL", "pg_isready -q -d $$POSTGRES_DB -U $$POSTGRES_USER"]
            interval: 10s
            timeout: 5s
            retries: 5
    futababot:
        build: .
        container_name: futababot
        depends_on:
            postgres:
                condition: service_healthy
        tty: true
        env_file:
            - src/.env.development
volumes:
    postgres-data:

内容的提问来源于stack exchange,提问作者secondubly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 05:34:51