-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a reference implementation of port forwarding #22
Comments
👍On this one. While you can use |
I would love this feature and I would try to make an implementation draft, but I have a couple of questions.
|
I was thinking of dynamic port forwarding where we could start something along the lines of E.g., we have implemented that in the Dev Containers extension for VS Code by locally listening on ports and forward any connections using |
@chrmarti your example was a helpful confirmation, I had to reverse engineer VS Code to get that inside. I added 'static' forwarding via devontainer.json in this branch (https://github.com/MunsMan/devcontainercli/tree/port_forwarding), there it implemented via the Docker CLI and the publish option. Currently, For automatic forwarding, should it be a feature then? When we demand code in the container, it should be a feature. I was thinking if forwarding is possible by mounting sockets via volumes into the container, but I will build a prototype for myself first. |
I built a prototype for automatic forwarding ports via a UNIX Socket (I had the assumption that WSL should support that), but even macOS didn't support sharing UNIX Sockets via a volume. The macOS support will not come in the near future (docker/for-mac#483). Due to the missing support for Unix Sockets on the other platforms, I'm considering using one static Port and Multiplexing all the other ports through it. A small program needs to run in the Container, scan for new ports and forward all traffic though the port. I would build the program in Rust, and then the CLI would need to pull the container corresponding binary and mount it into the container. The execution can be started via the |
I finished my prototype and when configured it works well for me. I published it in my It is pretty lightweight, especially compared to using VS Code for just auto-forwarding. Feedback is highly appreciated. Cheers |
@MunsMan Thank you for your efforts to actually implement this feature. This is the single feature that is preventing me from moving to devcontainers as a standard. Without this, using devcontainers without any specific tooling is simply impossible. If I have some free time, I will try out your code. |
Any progress on this? It would help us a lot! 🤩 |
For anyone interested in this topic, I have implemented the desired functionality using a Python script called devcontainer-cli-port-forwarder. This solution is based on @chrmarti's suggestion to utilize "onCreateCommand": "sudo apt update && sudo apt install -y socat",
"initializeCommand": "python3 .devcontainer/devcontainer-cli-port-forwarder/forwarder.py &"
|
Until forwardPorts support is complete, how about treating forwardPorts as an alias for addPort? It would require some workaround (e.g., add server process option I think this behavior is effective when using an already existing |
@chrmarti Can you please share ETA for this issue? |
The specification includes port attributes, but the dev container CLI doesn't include port forwarding support.
The text was updated successfully, but these errors were encountered: