📂
VS Code + Docker Desktop デフォルトが親ディレクトリーをマウントする設定の理由
経緯
VS Code のコマンドパレット (Ctrl+Shift+P, ⇧⌘P, または F1) で
[Add dev container configuration files...] を選択すると追加される
Developing inside a Container の設定ファイルが、
2023 年頃、次のように変更されました:
.devcontainer/docker-compose.yml
version: '3.8'
services:
# Update this to the name of the service you want to work with in your docker-compose.yml file
your-service-name-here:
# ~~~ 中略 ~~~
volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- - .:/workspaces:cached
+ - ..:/workspaces:cached
devcontainer.json
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
{
// ~~~ 中略 ~~~
// The optional 'workspaceFolder' property is the path VS Code should open by default when
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
- "workspaceFolder": "/workspace"
+. "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}"
// ~~~ 中略 ~~~
}
[Add dev container configuration files...] の使い方については次の記事を参照お願いします:
理由
Developing inside a Container の方式の 1 つである
clone repository in container volume を行う際の不具合のために
デフォルトの設定が変更となったようです:
実際の仕様変更は次で行われています:
clone repository in container volume については次の記事で詳しく解説されています:
clone repository in container volume ではない場合の問題
この設定は
clone repository in container volume ではない Developing inside a Container をするとき、
リポジトリーの兄弟ディレクトリーがマウントされるので
次のようなリスクがあるため、筆者は昔のデフォルト: /workspace
に戻しています:
- 意図しないアクセス
- パフォーマンス低下
- 意図しないセキュリティ的な問題
ちなみに、このことは公式ドキュメントで殆ど解説されておらず、
むしろ /workspace
のまま解説されていることが多いです
例:
Discussion