Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify listening address 0.0.0.0 for forwarded port in VSCode Remote Containers

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:

  • OS: macOS 10.15.7
  • VSCode: 1.57.0
  • VSCode Remote Containers extension: 0.183.0
like image 811
Alvin Leung Avatar asked Mar 01 '23 13:03

Alvin Leung


2 Answers

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

like image 76
Olivier Latorre Avatar answered May 17 '23 10:05

Olivier Latorre


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.

enter image description here

You can find the (official reference)[https://code.visualstudio.com/docs/remote/devcontainerjson-reference] of appPort parameter.

like image 39
HarryQ Avatar answered May 17 '23 10:05

HarryQ