0

When debugging a Node.js application, I expect the command node index.js --inspect=5858 to make my index.js file debuggable on the port 5858.

When I run the application outside of Docker, on my host computer, I'm able to debug the application in Chrome Dev Tools. I did the same inside of Docker and Chrome Dev Tools is unable to access the debugger on port 5858.

As you can see, port 5858 is exposed to the host computer for debugging:

version: '2'
services:
  server:
    build: .
    command: node index.js --inspect=5858
    volumes:
     - .:/app
    ports:
     - "8000:8000"
     - "5858:5858"
    environment:
     - NODE_ENV = "development"

I've specified localhost:5858 and 127.0.0.1:5858 network endpoints in Chrome Dev Tools, though still Dev Tools does not connect to it automatically as it suggests.

This seems to be an issue with my Docker setup though as you can see, I have exposed the port to the host computer. What could be the issue? Thanks.

4
  • Have you tried to get into your container's shell and see if localhost:5858 is up and running? If not, try docker exec -it container_id sh Commented Aug 9, 2017 at 16:42
  • @serey I checked that it's running in Docker with netstat -tulpn and port 5858 is running with program name 45/node so it is running Commented Aug 9, 2017 at 17:39
  • @PavSidhu Did you exported the port 5858 at Dockerfile? Commented Aug 9, 2017 at 19:10
  • @CauêAlves I just tried that and had no luck. In Kitematic, it shows that the ports 5858 and 8000, so it appears that they are being exposed properly. Commented Aug 9, 2017 at 19:25

1 Answer 1

3

The issue is that when you are running it inside the container it is listening only to localhost by default. So you have two options

Use host network

Add network_mode: host to your service and remove the port mappings. Not an ideal thing to do

Make sure nodejs listens to every IP

Change

command: node index.js --inspect=5858

to

command: node --inspect=0.0.0.0:5858 index.js

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.