別のローカルファイルのマウントを追加する

注意: GitHub Codespaces では、ローカルファイルシステムのマウントはサポートされていません。このシナリオでリモートフォルダーをマウントする方法については、リモート Docker ホスト上のコンテナー内での開発を参照してください。

devcontainer.json で参照している内容に基づいて、次の適切な手順を実行することで、任意のローカルフォルダーにバインドされたボリュームを追加できます。

  • Dockerfile またはイメージ: 同じファイルの mounts プロパティ (VS Code 1.41+) に以下を追加します

    "mounts": [
      "source=/local/source/path/goes/here,target=/target/path/in/container/goes/here,type=bind,consistency=cached"
    ]
    

    ローカル環境変数やワークスペースのローカルパスを参照することもできます。たとえば、これにより、macOS/Linux では ~ ($HOME)、Windows ではユーザーのフォルダー (%USERPROFILE%) とワークスペース内のサブフォルダーが別の場所にバインド マウントされます

    "mounts": [
        "source=${localEnv:HOME}${localEnv:USERPROFILE},target=/host-home-folder,type=bind,consistency=cached",
        "source=${localWorkspaceFolder}/app-data,target=/data,type=bind,consistency=cached"
    ]
    

動画: ローカルマシンから開発用コンテナーに追加のフォルダーを追加する



  • Docker Compose: 適切なサービスの docker-compose.yml を次の内容で更新(または拡張)します

    version: '3'
    services:
      your-service-name-here:
        volumes:
          - /local/source/path/goes/here:/target/path/in/container/goes/here:cached
          - ~:/host-home-folder:cached
          - ./data-subfolder:/data:cached
         # ...
    

すでにコンテナをビルドして接続している場合は、コマンドパレット (F1) から Dev Containers: Rebuild Container を実行して変更を反映させてください。それ以外の場合は、Dev Containers: Open Folder in Container... を実行してコンテナに接続してください。

© . This website operates independently and is not affiliated with or endorsed by Microsoft. All brand names, logos, and trademarks are the property of their respective owners.