0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windowsで devcontainer を使うときの settings.json 整理(Docker / Podman / WSL)

0
Posted at

はじめに

Windows で VS Code の Dev Containers を使うとき、コンテナランタイムの置き場所で settings.json の中身が変わります。

この記事では次の3パターンについて、必要な設定だけを整理します。

パターン 必要な設定
Windows に Docker Desktop ほぼ不要
Windows に Podman dockerPath / dockerComposePath を差し替え
WSL 内に Docker WSL 側の設定 or executeInWSL

前提として、拡張機能 ms-vscode-remote.remote-containers(Dev Containers)を入れておきます。

設定ファイルの場所

  • ユーザー設定: Ctrl + Shift + P → Preferences: Open User Settings (JSON)
  • WSL 側の設定: WSL に接続した状態で Preferences: Open Remote Settings (JSON)(Remote [WSL])

1. Docker を Windows にインストールしている場合

Docker Desktop を入れていれば、docker が PATH に通っているので追加設定は不要です。

{
  "dev.containers.dockerPath": "docker"
}

これはデフォルト値なので、書かなくても動きます。

2. Podman を Windows にインストールしている場合

Dev Containers は docker コマンドを呼ぶので、実行ファイルを Podman に差し替えます。

{
  "dev.containers.dockerPath": "podman",
  "dev.containers.dockerComposePath": "podman-compose"
}
  • Podman 側で podman machine init / podman machine start を済ませておく
  • compose を使わない devcontainer なら dockerComposePath は不要
  • podman-compose は別途インストールが必要(pip install podman-compose)

3. Docker を WSL にインストールしている場合

3-A. WSL に接続して使う(推奨)

VS Code の WSL 拡張で WSL に接続し、その中でフォルダを開きます。Dev Containers 拡張は WSL 側で動くので、WSL 内の docker がそのまま使われます。

Windows 側の設定は不要で、必要なら Remote [WSL] の設定に書きます。

{
  "dev.containers.dockerPath": "docker"
}
  • プロジェクトは WSL のファイルシステム(~/work/...)に置く。/mnt/c/... は遅い
  • WSL 内で docker ps が通ることを先に確認しておく

3-B. Windows 側の VS Code から WSL の Docker を使う

WSL に接続せず、Windows 側の VS Code のまま WSL の Docker を呼ぶ場合です。

{
  "dev.containers.executeInWSL": true,
  "dev.containers.executeInWSLDistro": "Ubuntu"
}
  • executeInWSLDistro はディストロ名(wsl -l で確認)に合わせる
  • 3-A のほうがパスの問題が起きにくいので、基本は 3-A

まとめ

パターン settings.json
Docker Desktop (Windows) 不要
Podman (Windows) dockerPath: "podman" + dockerComposePath: "podman-compose"
Docker (WSL) 接続して使う 不要(Remote [WSL] に dockerPath を書くのは任意)
Docker (WSL) Windows側から使う executeInWSL: true + executeInWSLDistro
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?