My setup is VS Code with a dev container. When I start an application that produces output that looks like a URL, VS Code will extract the port number and automatically forward that port. This process is described in some detail here.
My question is twofold:
What is the advantage of automatically forwarding ports?
How do I effectively prevent VS Code from automatically forwarding any port?
Solutions I considered and tested include using settings such as:
{
// Prevent VS Code's automatic port forwarding
"remote.autoForwardPorts": false,
"remote.restoreForwardedPorts": false,
"remote.portsAttributes": {
"1-65000": {
"label": "Application",
"onAutoForward": "ignore"
}
},
}
I have experimented with these settings at the user level, at the dev container level (aka remote), and at the workspace level. Furthermore, I've tried these settings in devcontainer.json
as well. I've also rebuilt the dev container to ensure settings were applied.
However, I didn't have much luck with any of this. VS Code keeps automatically forwarding ports. I'm looking for a durable solution.