How to forward devcontainer port to a different local port?

357 Views Asked by At

I have multiple devcontainers running on a remote server and I'm connecting to them from vs code. All of these containers have ssh enabled on port 22. "forwardPorts": [22] in devcontainer.json gives me no option to map port 22 of a devcontainer on a remote server to port 23 of my laptop. Which means, I have port forwarding to only one of these containers from my local development machine at any time.

"appPort": ["23:22"], allows me to map port 23 to port 22 of a container, but then that is only available on the remote server that is hosting docker (and containers).

I'm sure I'm missing something here: vs code already allows port forwarding of a port inside the container to a local port: 22 inside the container, 22 on my laptop, connected to remote server via ssh. There must be a way to configure it to use a different local port, but I have failed to find it.

I can create another ssh session to remote host and do port mapping using that so that I have laptop -> ssh[map local 23 to remote 23] -> server and connect to local 23 but there must be another way supported by devcontainers spec, or so I assume.

0

There are 0 best solutions below