Running the command docker run -p 9222:9229 --name node-inspect-test -d node:alpine node --inspect-brk -e 'console.log("hello world")'
should expose the node.js inspector on port 9222
on the Docker host.
Running curl http://localhost:9222/json
results in curl: (56) Recv failure: Connection reset by peer
.
Requesting the same endpoint from within the container with docker exec -it node-inspect-test wget -qO- http://localhost:9229/json
succeeds.
Why does the exposed port 9222
not get forwarded to the internal port 9229
successfully?
I'm running Docker version 17.06.0-ce, build 02c1d87 on Ubuntu 16.04.2.
You can expose a port through your Dockerfile or use --expose and then publish it with the -P flag. This will bind the exposed port to your Docker host on a random port (verified by running docker container ls ). You can expose a port through your Dockerfile or use --expose and then publish it with the -p 80:80 flag.
In order to make a port available to services outside of Docker, or to Docker containers which are not connected to the container's network, we can use the -P or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host to the outside world.
Docker also finds ports you expose with --expose 8080 (assuming you want to expose port 8080). Docker maps all of these ports to a host port within a given epehmeral port range . You can find the configuration for these ports (usually 32768 to 61000) in /proc/sys/net/ipv4/ip_local_port_range .
The node-debug command will load Node Inspector in your default browser. NOTE: Node Inspector works in Chrome and Opera only. You have to re-open the inspector page in one of those browsers if another browser is your default web browser (e.g. Safari or Internet Explorer).
By default node inspector listens on the loopback interface. The --inspect-brk
flag has the option of specifying host and port. In order to have the debugger listen on all interfaces so that it is accessible via the Docker host, use the flag --inspect-brk=0.0.0.0:9229
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With