vscode-remote-release
vscode-remote-release copied to clipboard
Add `open` command to `@vscode/dev-container-cli`
This issue is a follow-up of https://github.com/microsoft/vscode-remote-release/issues/5415#issuecomment-981373936.
Now the devcontainer
cli is available to be installed from npm with npm install --global @vscode/dev-container-cli
, but it's missing the open
command.
My use case is to have it installed as part of my dotfiles, so that I get the devcontainer command installed every time I bootstrap a new computer with my dotfiles installation script (which also manages to install VS Code, by the way).
However, I use a similar dotfiles experience as a managed development environment for the my team, and there, I have a guide where I tell them to:
- Install our dotfiles to bootstrap their dev env
- Clone any of our company's repository
-
devcontainer open
it
But it would be too cumbersome if I had to write instructions like:
- First open VS Code
- F1 -> Install Devcontainer CLI
- Answers the questions on the screen
And then get back to the part where devcontainer open
would actually work.
There was a version in the past that supported the open
command. It appears to me that this is a case of feature degradation. The documentation at https://code.visualstudio.com/docs/remote/devcontainer-cli the output of devcontainer --help
lists a command named open
:
$ devcontainer --help
devcontainer <command>
Commands:
devcontainer open [path] Open a dev container in VS Code
devcontainer build [path] Build a dev container image
Options:
-h, --help Show help [boolean]
--disable-telemetry Disable telemetry [boolean] [default: false]
However, a few days ago and after following the instructions to install it on a new Ubuntu distro (WSL2), the output of devcontainer --help
looks as follows:
$ devcontainer --help
devcontainer <command>
Commands:
devcontainer build [path] Build a dev container image
Options:
-h, --help Show help [boolean]
--disable-telemetry Disable telemetry [boolean] [default: false]
As you can see it list only build
as a command. open
is no longer available.
The build
command, which is now the only one currently supported, is not that useful in our setup. Building of the dev container and its dependencies happens automatically via .devcontainer
or .devcontainer.json
if needed when VS Code opens the directory in the dev container.
@ManfredLange There are two ways to install the CLI: As part of the Remote-Containers extension and as an NPM package. Currently the NPM package does not support open
because it lacks the association with your VS Code install. This feature request is about improving that.
When you use the CLI installed as part of Remote-Containers, the open
command is available. (If it is not, it would be a bug.)
I just wrote a similar issue before searching and finding this - doh. My approach, though, was as a bug report on that the feature difference is undocumented. So, if it's not just a quick fix to harmonise features with regards to installation method, I could suggest someone documents these facts, suggestively around "You may also install the CLI from the command line."
It didn't feel right to dump my bug report in the issues after finding this, but let me know if you think it'd help to get it documented. Thanks for your work. (If documentation is a community effort, feel free to point me in that direction.)
PS. I actually found #2900 before this
https://github.com/microsoft/vscode-docs
The installation method via the Remote-Container extension in fact installs it..... On my Windows host.
However, I am using WSL2 (Ubuntu 20.04) installed and that is where I want to install the devcontainer-cli. The extension doesn't do that. And when installing via npm
then the open
-command is missing.
So, while it's useful to know that the devcontainer-cli can be installed via the extension, it doesn't appear in WSL2.
The installation method via the Remote-Container extension in fact installs it..... On my Windows host.
However, I am using WSL2 (Ubuntu 20.04) installed and that is where I want to install the devcontainer-cli. The extension doesn't do that. And when installing via npm
then the open
-command is missing.
So, while it's useful to know that the devcontainer-cli can be installed via the extension, it doesn't appear in WSL2.
It does appear, though, when I restart the computer. So the following seems to work:
- Install VS Code
- Install Remote-container extension
- In VS Code from the Command Palette (F1) execute
Remote-Containers: Install devcontainer CLI
- Reboot your computer
-
devcontainer --help
in a WSL2/Ubuntu terminal should now show optionopen
as well.
This recipe applies to this set up:
- Windows 10 or 11
- WSL2 with some Linux distro (e.g. Ubuntu)
- VS Code
- Docker Desktop, configured to use WSL2
@ManfredLange Thanks, that works! In my case, it was enough to restart the WSL with wsl.exe --shutdown
. No need to reboot the computer.
In my case, after restarting WSL2, running devcontainer --help
returns
wslpath: Invalid argument
Failed to determine Dev Containers path
Has anyone debugged that symptom?
I built my own code
wrapper that has a --devcontainer
flag. Usage:
code --devcontainer ~/repos/myproject
It works for when VS Code is running on Linux, when running from within a remote SSH session (in or out of the vscode integrated terminal) and even within a remote tunnel session.
https://github.com/felipecrs/dotfiles/blob/master/home/dot_local/bin/executable_code https://github.com/felipecrs/dotfiles/pull/118
It is immensely useful and timesaving for me, so I expect other people to benefit from it too. Simply install it to your ~/.local/bin/code
and you should be good to go.
https://github.com/user-attachments/assets/225db564-3931-46be-8769-c4e70dc274cb