79534374

Date: 2025-03-25 17:08:31
Score: 0.5
Natty:
Report link

It's not possible to forward remote port to local machine in VSCode

VSCode doesn't support port forwarding if you're connected to a remote machine.

Currently, port forwarding only works to expose locally-running services. It doesn't work in remote connections yet, although we expect it to in the future.

Depending on your scenario, you may want to use the VS Code Remote - Tunnels extension to tunnel into a remote machine. You can learn more in the Remote - Tunnels documentation.

Alternative solution

We can forward Remote Port to Local Environment using 3rd party tools like socat.

Here is instructions how to run Docker project on Remote host using VSCode SSH connection and VSCode containers.

  1. Forward port 80 to port 8080 in VSCode using SSH connection;
    enter image description here

  2. Forward Remote Server port 80 to your Local port 8080 by running socat command in VSCode terminal (socat should be installed to use it):

    sudo socat TCP-LISTEN:80,fork TCP:127.0.0.1:8080
    

    WARNING:
    NEXT STEPS SHOULD BE DONE IN THE ANOTHER VSCODE WINDOW.
    TWO (2) VSCODE WINDOWS SHOULD BE OPENED.

    FIRST ONE FOR PORT REDIRECTION USING SSH CONNECTION.
    SECOND ONE FOR CODING USING VSCODE CONTAINER.

  3. Run VSCode container and enjoy coding remotely;

Error: port 8080 is already used

  1. Check which app is using port 8080 by typing lsof -i tcp:8080 in terminal;

  2. Find PID in the output and kill the application sudo kill <PID> ;

References

Reasons:
  • Blacklisted phrase (1): How do I
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Yaroslav Borodii