2

I'm trying to remote debug nodejs 9 inside docker.

> testnodedockerproj@0.0.0 debug /home/deb
> node --inspect=9229 ./bin/www
Debugger listening on ws://127.0.0.1:9229/75db828f-4b4b-491c-99d1-0eb60a82e45c
For help see https://nodejs.org/en/docs/inspector

http://localhost:3100/ responds

GET /robots.txt 404 1752.471 ms - 905
GET / 304 1838.729 ms - -
GET /stylesheets/style.css 304 114.501 ms - -

But I can't connect to ws://127.0.0.1:9229/75db828f-4b4b-491c-99d1-0eb60a82e45c.

The docker compose file has this port config:

ports:
    - "3100:3000"
    - "9339:9229"

I can connect to the node debug url from inside the docker container. But I can't reach it from my host system. The expected endpoint should be ws://127.0.0.1:9339/75db828f-4b4b-491c-99d1-0eb60a82e45c and it is unaccessible.

Is there any specific docker config which enables the connection to the web socket?

How do I reach this node debug endpoint?

@Update

I've managed to connect to the debug endpoint.

The node debug command should be:

node --inspect=[::]:9229 ./bin/www

In this way I can connect to the port 9339 and attach a debugger.

user2776801
  • 131
  • 8
  • Just to clarify: you're trying to connect **remotely** and using this notation `ws://127.0.0.1:9339` from your host machine? – Azuloo Nov 28 '17 at 15:16
  • Yes, Node is in Docker on my desktop. So, localhost should do, I hope. – user2776801 Nov 29 '17 at 12:50
  • So it's not remote, it's just in your docker container. You for sure need to use this port `9339` and should be able to connect here `ws://127.0.0.1:9339`. – Azuloo Nov 29 '17 at 13:24
  • Yes, I am supposed to be able, but I'm not. http://127.0.0.1:3100 is accessible, but ws://127.0.0.1:9339 is not. – user2776801 Nov 29 '17 at 14:04
  • What exact error you're getting? – Azuloo Nov 29 '17 at 14:06
  • Well, I try in different ways. Chrome says: This site can’t be reached, ERR_DISALLOWED_URL_SCHEME I try websocket connection in PowerShell (my host is Windows): (New-Object System.Net.WebSockets.ClientWebSocket).ConnectAsync($url, $CT) but it says the destination is not reachable – user2776801 Nov 29 '17 at 15:24
  • I tried to set up a static ip to the container as described here [static-ip-to-docker-container](https://stackoverflow.com/questions/27937185/assign-static-ip-to-docker-container). But I can't make it work. – user2776801 Nov 29 '17 at 15:35

2 Answers2

5

The node debug command should be:

node --inspect=[::]:9229 ./bin/www
user2776801
  • 131
  • 8
0

So here how I managed to make it work:

  1. You have the container with let's say this IP: 172.1.1.10
  2. Open up Chrome dev tools: chrome://inspect/#devices
  3. Select configure and add new address and port: 172.1.1.10:9229
  4. Start the container
  5. Run the following command (I have Ubuntu 16.04): docker-compose exec <conainer name> node --inspect=172.1.1.10:9229 <path-to-task>
  6. Refresh you Chrome page and if you set everything correctly you will see your container under Remote Target label.
Azuloo
  • 461
  • 2
  • 9