2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【VSCode】Dev Containersをコマンドで起動する方法

Last updated at Posted at 2023-02-24

VSCodeのコマンドパレットからDev Containers: Install devcontainer CLIを選択し実行します。

VSCodeからインストールした場合にはdevcontainer openコマンドが使用できます。

$ devcontainer --help
devcontainer <command>

Commands:
  devcontainer open [path]          Open a dev container in VS Code
  devcontainer up                   Create and run dev container
  devcontainer set-up               Set up an existing container as a dev container
  devcontainer build [path]         Build a dev container image
  devcontainer run-user-commands    Run user commands
  devcontainer read-configuration   Read configuration
  devcontainer features             Features commands
  devcontainer templates            Templates commands
  devcontainer exec <cmd> [args..]  Execute a command on a running dev container

Options:
  --help     Show help                                                                     [boolean]
  --version  Show version number                                                           [boolean]

devcontainer@0.29.0 /Users/username/.vscode/extensions/ms-vscode-remote.remote-containers-0.275
.1

次のようにdevcontainer openコマンドを実行するとカレントディレクトリでDev Containerを開けます。

devcontainer open .

npmでインストールする

次のコマンドを実行することでインストールできます。

npm install -g @devcontainers/cli

npmでインストールした場合にはdevcontainer openコマンドは使用できません。

$ devcontainer --help
devcontainer <command>

Commands:
  devcontainer up                   Create and run dev container
  devcontainer build [path]         Build a dev container image
  devcontainer run-user-commands    Run user commands
  devcontainer read-configuration   Read configuration
  devcontainer features             Features commands
  devcontainer templates            Templates commands
  devcontainer exec <cmd> [args..]  Execute a command on a running dev container

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

しかし次のようにコマンドを実行するとDev Containerを開けます。

code --folder-uri "vscode-remote://dev-container%2B$(printf "%s" "/path/to/host/project" | xxd -p -c 256)/path/to/devcontainer/workspaceFolder"

上記の記述は~/Library/Application Support/Code/User/globalStorage/storage.jsonで見つけることができます。

`grep "vscode-remote://dev-container%2B$(printf "%s" "/path/to/host/project" | xxd -p -c 256)/path/to/devcontainer/workspaceFolder" \
    "${HOME}/Library/Application Support/Code/User/globalStorage/storage.json"`
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?