How does VSCode [Remote Development] [Forward Port] work?

Viewed 4666

When using VSCode Remote Development Open Folder in Container to develop in docker container in Mac, I can not find:

  • Any info about the port by docker inspect containerId
  • Any port config in Dockerfile

But I can still access the service in container from host browser.

1 Answers

VS Code uses SSH Tunnel to connect to remote machine. The port forwarding is simply creating this tunnel. You can do it without vscode with below command if you have ssh client installed. You have to run this command from loclhost shell prompt. [I assumed we want to connect to port 8080 on remote-machine using localhost:8085]

ssh -L 8085:remote-machine-ip:8080 remote-machine-ip

now, from your browser, if you go to http://localhost:8085 it will show content from remote-machine's 8080 service

Related