vscode-remote-release icon indicating copy to clipboard operation
vscode-remote-release copied to clipboard

Add `open` command to `@vscode/dev-container-cli`

Open felipecrs opened this issue 3 years ago • 8 comments

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:

  1. Install our dotfiles to bootstrap their dev env
  2. Clone any of our company's repository
  3. devcontainer open it

But it would be too cumbersome if I had to write instructions like:

  1. First open VS Code
  2. F1 -> Install Devcontainer CLI
  3. Answers the questions on the screen

And then get back to the part where devcontainer open would actually work.

felipecrs avatar Nov 29 '21 10:11 felipecrs

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 avatar Dec 18 '21 21:12 ManfredLange

@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.)

chrmarti avatar Dec 22 '21 07:12 chrmarti

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

vike2000 avatar Jan 09 '22 05:01 vike2000

https://github.com/microsoft/vscode-docs

felipecrs avatar Jan 09 '22 16:01 felipecrs

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.

ManfredLange avatar Mar 29 '22 06:03 ManfredLange

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:

  1. Install VS Code
  2. Install Remote-container extension
  3. In VS Code from the Command Palette (F1) execute Remote-Containers: Install devcontainer CLI
  4. Reboot your computer
  5. devcontainer --help in a WSL2/Ubuntu terminal should now show option open as well.

This recipe applies to this set up:

  1. Windows 10 or 11
  2. WSL2 with some Linux distro (e.g. Ubuntu)
  3. VS Code
  4. Docker Desktop, configured to use WSL2

ManfredLange avatar Mar 29 '22 06:03 ManfredLange

@ManfredLange Thanks, that works! In my case, it was enough to restart the WSL with wsl.exe --shutdown. No need to reboot the computer.

manualbashing avatar Jul 21 '22 07:07 manualbashing

In my case, after restarting WSL2, running devcontainer --help returns

wslpath: Invalid argument
Failed to determine Dev Containers path

Has anyone debugged that symptom?

jyasskin avatar May 02 '24 00:05 jyasskin

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

felipecrs avatar Jul 11 '24 23:07 felipecrs