philipp
philipp

Reputation: 16515

Debug Node (>=6.3) from a docker container

I have a docker container which uses pm2 to run node like so:

#process.yml
apps:

  - script: ./index.js
    name: client
    watch: true
    args: --inspect

 #Dockerfile

 CMD pm2-docker process.yml

As I could read in that post: The node inspector has arrived in the core of node.js and running a script like so:

node --inspect <somescript.js>

gives some output on the commandline like that: chrome-devtools://… and navigating to that url in chrome, will fire up node-inspector.

How can I do that for a node instance that lives inside a container, but should be debugged from the host.

UPDATE

I could manage to start the debug process by changing two things:

  1. node_args: --inspect=localhost:9080
  2. docker run ... -p 9080:9080

But that brings up one Problem: The URL to use is displayed on the commandline right after node --inspect=... ... is executed, but when running the docker container that information goes down to the logs somewhere. So how can I access the url from there?

Upvotes: 1

Views: 686

Answers (1)

Julian
Julian

Reputation: 2822

You simply publish the required with -p 9229:9229 or

ports: 
  - 9229:9229

in the docker-compose, and then start it with pm2 and the --inspect arg or directly with node --inspect index. The url will then be printed out and you can simply use it in chrome like without docker.

To find that line afterwards you can use

docker-compose logs service-name | grep chrome-devtools

or

docker logs container-id 2>&1 | grep chrome-devtools

Upvotes: 2

Related Questions