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.
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.
Forward port 80 to port 8080 in VSCode using SSH connection;
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.
Run VSCode container and enjoy coding remotely;
Check which app is using port 8080 by typing lsof -i tcp:8080
in terminal;
Find PID in the output and kill the application sudo kill <PID>
;