I am developing inside a docker container using the VSCode Remote Containers extension. I start a server inside the container which listens at port 3342 and would like to access the webpage using other devices in the same network.
I forward port 3342 inside the Ports tab and I am able to open the webpage in my host OS using localhost:3342
and 127.0.0.1:3342
, but failed when using my local IP address 10.10.11.90:3342
.
I checked the listening ports in my host OS:
> sudo lsof -nP -iTCP:3342 | grep LISTEN
Code\x20H 4181 alvin 27u IPv4 0x65c113c13860c1b7 0t0 TCP 127.0.0.1:3342 (LISTEN)
It seems that VSCode is only listening at 127.0.0.1
.
Is there a way for me to tell VSCode to listen at 0.0.0.0
so that it accepts requests from all network interface?
My configuration:
In VSCode settings, set
Remote: Local Port Host
allInterfaces
If it's set to "localhost", devContainers forwarded ports will only listen to 127.0.0.1.
When set to "allInterfaces, it will listen to 0.0.0.0.
See screenshot for context
For VSCode: 1.69.0 on Ubuntu, the forward setting page is not available.
It is verified that we can do allinterface port forwarding by modifying the devcontainer.json by adding in the following parameters.
"appPort": ["8107:8107"],
After relaunching your container, the port forwarding can be verified in the "port" tab of the tool bar.
You can find the (official reference)[https://code.visualstudio.com/docs/remote/devcontainerjson-reference] of appPort parameter.
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