-
Notifications
You must be signed in to change notification settings - Fork 308
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
Attach to running docker container by name in CLI and document code remote CLI options #5278
Comments
There is now a |
Hey @chrmarti, |
Hi @joshsedl, still on the backlog. To follow what we are currently up to I recommend checking the current iteration plan. Usually the only pinned issue at the top of https://github.com/microsoft/vscode-remote-release/issues. |
Ok, thanks for the tip! |
Since we are tracking this issue here now, I just wanted to quote my proposal from #5944, to attach VSCode to a container with additional setting and extension flags!
|
Hello @chrmarti, this is a very useful feature. |
@g-kartik You could try using this: |
Thank you @chrmarti . It worked. Could not be more happy! |
For some reason,
So instead I am using a differen (probably overcomplicated) command: |
I had the issue with my ddev-vscode-devcontainer addon to open containers in VScode. It came down to how the terminal would "wrap" longer names into columns. Using xxd, I change the default from 16 to 64 which resolved my issue.
|
Thanks, @tyler36! Yea, I probably skipped on "xxd" too fast, Never the less I'll rather use |
Thanks @joshsedl . I use WSL ubuntu and it was the solution I stumbled across and worked. Before my post, I checked that my WSL OpenSUS had |
I combined the new devcontainer cli with the approach presented here: CONTAINER_NAME_OR_ID=$(devcontainer up --workspace-folder . | jq -r .containerId) /usr/bin/code --folder-uri vscode-remote://attached-container+$(printf "$CONTAINER_NAME_OR_ID" | od -A n -t x1 | sed 's/ *//g' | tr -d '\n')/workspace This way I have a oneliner that will start a devcontainer defined in the current working directory and automatically attaches vscode to it. Without using the whole You can even put it into an alias inside your alias dc="CONTAINER_NAME_OR_ID=\$(devcontainer up --workspace-folder . | jq -r .containerId) && /usr/bin/code --folder-uri vscode-remote://attached-container+\$(printf \"\$CONTAINER_NAME_OR_ID\" | od -A n -t x1 | sed 's/ *//g' | tr -d '\n')/workspace" The only thing I don't like about this approach, is that it doesn't fully respect all the I gave this script a shot: https://gist.github.com/ilyasotkov/27e77fd4a1a045bb17f5bcf7f20c1f2e And with a simple alias like so: alias devcontainer="/usr/bin/code --folder-uri \$(python3 /workspace/dev-setup/make_devcontainer_folder_uri.py)" It either starts a new devcontainer from the definition file in your current working directory or will attach to an already existing devcontainer. |
@tuunit, thanks for sharing! You say, that you start a devcontainer through "devcontainer up" and attach vscode to it. Do you know if the devcontainer cli can also take a devcontainer.json and use it to attach to an existing container? I saw "devcontainer up --mount", but I am unsure if that does what this issue is originally about. |
How would you attach a container to a container 🤔 Or do I misunderstand what you try to accomplish? |
@tuunit, sorry not very well worded, I updated my comment. Basically, what I mean is, that an attached vscode supports a subset of devcontainer.json properties. So I basically want to attach to container xyz using the settings defined in a custom devcontainer.json. Maybe, that's what your snippet is doing already and I misunderstood the first part of your comment! |
Ah okay, if you read the last sentence of my original comment. It will answer your question:
Meaning if a devcontainer defined by your |
Thanks a lot @tuunit! That sounds great! 🎉 |
Ok, #5278 (comment), doesn't solve this issue's problem yet.
The talk is of a devcontainer, not a "normal" container to attach to. Meaning if I want to attach VSCode to my dev environment's web server container, I can not do that with the Although this could still be a future feature of https://github.com/devcontainers/cli. It might make sense to move this feature request there? |
Hi and thank you all very much for your hard work on vscode and vscode-remote! It's simply brilliant.
Context
We're using tools like https://github.com/drud/ddev or https://lando.dev/ to build and run smart development docker containers.
We're using VSCode Remote to attach to these running containers using the wonderful UI via F1 + Remote-Containers: Attach to Running Container ...
There we select the container we'd like to attach to and run it.
Problem
This works, but for developers like you and us the process isn't really perfect. It's clicky here, clicky there for a task where you'd expect to write a shell script and GO :)
I've read many similar issues, most are about how to start devcontainers / k8 or ssh remote connections.
Anyway it seems such CLI parameters aren't yet officially documented?
For our use-case (attaching to a running docker container by name from CLI / shell script) I couldn't find a viable solution. That's why I've written this feature request to document the CLI options and provide a clever way to start vscode from CLI / shell script attached to a running container by container name / id.
Proposed solution
Once again, thank you very much for your hard work on this wonderful project!
The text was updated successfully, but these errors were encountered: