Reputation: 8610
I feel like I am close to getting docker-compose and node-inspector playing nicely together but would love if someone could show me how they set up their docker-compose file along with an explanation for how it works.
Here's what my compose.yml file looks like with just the node app in it:
app:
image: my-node-app
volumes:
- '~/mycode:/app/code'
ports:
- "3000:3000"
command: /bin/bash
Also note I'm using Docker for Mac. (Although I don't think that should change much..)
I found a couple tutorials for getting for how to do it, but the information was either out of date or seemed incomplete. Here are the two main approaches (neither has worked for me yet):
1) From: https://github.com/seelio/node-inspector-docker/issues/1
app:
image: my-node-app
ports:
- "3000:3000"
command: /bin/bash
volumes_from:
- code
debugger:
image: node-debug
depends_on:
- app
# `service` instead of `container` for an easier cold start
network_mode: 'service:app'
volumes_from:
- code
code:
image: node
volumes:
- '~/mycode:/app/code'
2)
and from: https://keylocation.sg/our-tech/debugging-nodejs-in-docker-using-node-inspector :
debugger:
container_name: debugger
network_mode: host
extends:
service: base
volumes:
- /app/containers/debugger:/app/container
One little trick required was the addition of port 5858 mapping for the node-app container so that Node Inspector can see it as port 5858 on the host:
node-app:
ports:
- "5858:5858" # Port needs to be mapped to host so that debugger container can access it
Upvotes: 1
Views: 1739
Reputation: 8621
Node’s debug interface needs to know to be accessible outside of local network of Docker container, so the inspector should be started with
node --inspect-brk=0.0.0.0:9229 index.js
Replace index.js with whatever node thing you want to run.
--inspect-brk
is used instead of --inspect
so that debugger can be attached at start of the script, so that it can follow whatever it does, which allows the debugger to know whatever is happening, effectively allowing proper debugging.
The broadcast IP causes the inspector listen everything and not closing connections from outside of localhost (the default). 9229 is the default port.
Upvotes: 1
Reputation: 11
You have to add EXPOSE 5858
or EXPOSE 9229
in your app Dockerfile.
Upvotes: 1