I have a NestJs project using docker and I would like to debug it in VSCode.
In package.json, I have:
"start:debug": "nest start --debug 0.0.0.0:9229 --watch"
In docker-compose, I have:
version: '3.8'
services:
core-database:
image: postgis/postgis:latest
volumes:
- /tmp/rg-core/postgres/data:/var/lib/postgresql/data
environment:
- POSTGRES_DB=***
- POSTGRES_USER=***
- POSTGRES_PASSWORD=***
ports:
- 5433:5432
core-service:
container_name: core-service
working_dir: /usr/src/app
build:
context: .
dockerfile: ./Dockerfile.dev
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
ports:
- 9001:9001
#debugging port
- 9229:9229
# Database
- DB_HOST=***
- DB_PORT=5432
- DB_NAME=***
- DB_USER=***
- DB_PASSWORD=***
command: 'yarn run start:debug'
In launch.json, I have:
{
// 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": "Attach",
"port": 9229,
"request": "attach",
"localRoot": "${workspaceFolder}",
"type": "node",
"address": "0.0.0.0",
"restart": true,
"remoteRoot": "/usr/src/app",
"sourceMaps": true,
"skipFiles": [
"<node_internals>/**"
]
}
]
}
I’m running docker compose up and giving start debugging in VSCode, but it’s not stopping at the breakpoint.
Am I doing something wrong? how should it be done?
2
Answers
Was missing port 9229 export in Dockerfile.
In the package.json:
"dev": "nest start --debug 0.0.0.0:9229 --watch"
In the docker-compose:
In the launch.json:
In the Dockerfile:
I am trying to deal with the same problem for a few days now.
From my research, VS Code Debug Console by default is listening for
console.log
s. However NestJS Logger is logging tostdout/stderr
(process.stdout.write
), solaunch.json
needs the additional line:Sadly, it is still not enough to make it work.
To workaround this for now, I’m attaching a running container’s terminal to VS Code integrated terminal manually, executing
docker container attach --no-stdin <container-name>
.This is still not a real solution so I hope someone brings one. Thank you for raising this issue. Can you share the contents of your Dockerfile for full reference?