port-forwarding with many ports
Hello! For my application I need to port forward a great number of ports on my local machine from an up and running workspace.
This: coder port-forward my-ws --tcp p1 --tcp p2 --tcp p3 --tcp p4 --tcp p5 --tcp p6 ... doesn't look great. Can you suggest me a smarter way to achieve this ? Thank you all
21 Replies
@sarco if you run
coder port-forward --help
I think there's an example.
coder port-forward <workspace> --tcp 8080:8080 --tcp 9000:3000 --udp 5353:53
Is this what you're asking?No actually I'd like to avoid to type --tcp 50 times... i need to port forward a great number of ports so the resulting command:
coder port-forward workspace --tcp 1111 --tcp 2222 --tcp 3333 --tcp 4444 -tcp 6666 --tcp 7777 etc...
doesn't really looks readable.
What would be optimal? an array?
an array, or even better, a file where the ports are listed
like one line per port?
I opened an issue @sarco feel free to add onto it. Hope I got it basically right. Your feedback above made it kind of clear. https://github.com/coder/coder/issues/3766
GitHub
Forward a range of ports with the
port-forward
subcommand · Issue...A community user with multiple users in their deployment reported a feature request to improve the port-forward experience. Right now, you have to enter --tcp or --udp for each port. The request, a...
why not yes
Great! I'll follow the issue. In order to address my specific problem for the moment, I will just cycle over multiple coder port-forward command:
for port in ports:
coder port-forward my-ws --tcp port:port
Another way to achieve this in bash would be to define a
ports
array, e.g. via ports=(4000 4005 4010)
or reading from a file ports=($(<ports.txt))
and then running the port forward command like so:
what about having
--tcp 1111 2222 3333 4444 --udp 5555 6666
but this is clearly goodWe could take this principle and make
coder
work the way we want via a bash function (e.g. when places in .bashrc
)
Now we can type coder port-forward my-ws ./ports.txt
.
Obviously this is very rudimentary, and we may want to specify udp
instead of tcp
, but the above could be extended to support such use-cases.
I think we could be able to do something like --tcp 1111,2222,3333
, but I don't think our CLI library supports the space-separated values for a single flag.that's fine by me too
As soon as I may pass the array of ports to the --tcp options sounds good to me
What syntax would you propose? Like I mentioned to @Phorcys suggestion, we can't do
--tcp 1111 2222
, so --tcp "${ports[@]}"
probably won't happen. In theory --tcp "${ports[*]}
could work if we allowed space-separated ports in the single string, but I don't like how this syntax easily would lead to incorrect use (e.g. via [@]
).honestly comma-separated is good
I agree
Great, posted the suggestion on the GH ticket.
for this one i'm doing smth different -> port forward the ssh session to expose a socks proxy and use it on my browser to reach the exposed ports @sarco
ssh -D 65300 coder.$workspace
-> then use socks5://localhost:65300 as a proxy on your browser or anywhere else 😉ew
Beauty is in the eye of the beholder 😉
i mean hey it works
Sorry for my late reply, I did not check discord. Thank you @dedboi but I was looking for something more straightforward. However I am happy my request triggered the devs to implement this feature