Is there a way to open a folder in a container from the VSCode command line using the remote-containers extension?

Viewed 1883

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!

3 Answers

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 -p and the directory name basename "$(pwd)".

code --folder-uri="vscode-remote://dev-container+$(pwd | tr -d '\n' | xxd -p)/workspaces/$(basename "$(pwd)")"
Related