[英]Node vs-code debugger is showing unbound breakpoint in docker
經過大量探索后,我使 ts 調試器適用於特定端口,並且還需要在使用 nodemon 進行實時重新加載時編譯 .ts。 當我在沒有 docker 的情況下運行應用程序時,我得到了相同的未綁定斷點,但在更改啟動文件后它工作了。
然而,在 docker 中,調試器正在附加但帶有未綁定的斷點。 需要對"name": "my-service-docker",
發射.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": "my-service",
"type": "node",
"request": "attach",
"port": 9229,
"restart": true,
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"sourceMaps": true
},
{
"name": "my-service-docker",
"type": "node",
"request": "attach",
"port": 9230,
"restart": true,
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"sourceMaps": true
}
]
}
docker-compose.yml
# YML version
version: '3.8'
# Define all the services our book application needs
services:
my-service : # node application
container_name: my-backend-container
restart: always # automatically restart if the app fails
build:
context: .
dockerfile: Dockerfile
image: username/my-service
env_file:
- .env
depends_on:
- mongo
ports:
- 3000:3000
- 9230:9229
volumes:
- ./:/usr/src/app
- exclude:/usr/src/app/node_modules/
mongo: # database
expose:
- "4000"
image: mongo:5.0.6 # pull the mongo image from docker hub
logging:
driver: none # disable logging
ports:
- '27018:27017'
volumes:
exclude:
nodemon.json
{
"watch": ["src"],
"ext": ".ts,.js",
"ignore": [".git", "node_modules/**/node_modules"],
"execMap": {
"ts": "node --require ts-node/register -r tsconfig-paths/register"
},
"exec": "npx tsc&&node --inspect=0.0.0.0:9229 build/index.js"
}
package.json
...
///
///
"scripts": {
"start:dev": "NODE_ENV=development&&nodemon"
}
...
DockerFile
FROM node:16
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
ENV PATH=/usr/src/app/node_modules/.bin:$PATH
# If you are building your code for production
# RUN npm ci --only=production
COPY . .
EXPOSE 3000
CMD [ "npm", "run", "start:dev" ]
對於 docker,我們需要為 remoteRoot 設置正確的路徑:即 /usr/src/app
{
"name": "my-service-docker",
"type": "node",
"request": "attach",
"port": 9230,
"restart": true,
"sourceMaps": true,
"address": "localhost",
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/app",
"protocol": "inspector"
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.