Reputation: 143
I have created a .devcontainer/devcontainer.json file in the root of my source tree. But, is there something I can specify on the command line to automatically open the specified folder in that container? Or at least open up vscode within the container automatically (not necessarily the folder)?
I'm also curious if there is a similar option for attaching to a container (without having to open another window).
For the former - VS Code does provide a dialog asking if I want to reopen. That's not bad, I was just hoping there was some argument I could specify on the command line to do one better.
Thanks!
Upvotes: 11
Views: 6289
Reputation: 414
Here's a one-liner to open the current directory in a remote container. The --folder-uri
is constructed from the hex-encoded directory path pwd | tr -d '\n' | xxd -c 256 -p
and the directory name basename "$(pwd)"
.
code --folder-uri="vscode-remote://dev-container+$(pwd | tr -d '\n' | xxd -c 256 -p)/workspaces/$(basename "$(pwd)")"
Upvotes: 7
Reputation: 546
It's possible to open vscode directly into the container, but you need to create the hex value for the command.
See solution here => How to attach a remote container using vscode command line?
Upvotes: 2
Reputation: 661
If you would like to run the container outside of Visual Studio Code you can use a script I have created. See https://blog.wille-zone.de/post/run-devcontainer-outside-of-visual-studio-code/ for more information. The script itself can be found on Github https://github.com/BorisWilhelms/devcontainer
Upvotes: 2