Support devcontainer.json in sub-folder (`.devcontainer/**/devcontainer.json`)
From devcontainers/ci#212
Does this CLI work with .devcontainer/**/devcontainer.json (where ** is a sub-folder) from the specs?
https://containers.dev/implementors/spec/#devcontainerjson
The CLI only picks up .devcontainer/devcontainer.json and .devcontainer.json automatically. For configs in subfolders you would have pass their path with --config <path> to the CLI.
Thanks for the reply.
So at this point, is it still possible to add the functionality to the CI ?
I don't want to use Dev Container CI directly, I want to build an image from a definition file in a sub dir .devcontainer/subdir/devcontainer.json on GitHub Actions (devcontainers/ci#212).
The CI action could add an option to specify the config file. I think we don't want the CLI to search the subfolders automatically as that might result in multiple config files.
@stuartleeks What do you think?
So is this a difference between the spec and CLI behaviour? According to the spec "It is valid that these files may exist in more than one location, so consider providing a mechanism for users to select one when appropriate."
Current behavior is strange. Suppose that you setup the project describes here: https://code.visualstudio.com/remote/advancedcontainers/connect-multiple-containers.
Then execute the following commands we see odd behavior with the later containers not able to exec commands:
devcontainer up --workspace-folder ./ --config .devcontainer/node-container/devcontainer.json
{"outcome":"success","containerId":"3b07423bf02980316d80cb088c6013ade7550a59bc8b2a24defd8a1d20752303","composeProjectName":"devcontainer-multiple","remoteUser":"node","remoteWorkspaceFolder":"/workspace/node-src"}
devcontainer up --workspace-folder ./ --config .devcontainer/python-container/devcontainer.json
{"outcome":"success","containerId":"3b07423bf02980316d80cb088c6013ade7550a59bc8b2a24defd8a1d20752303","composeProjectName":"devcontainer-multiple","remoteUser":"node","remoteWorkspaceFolder":"/workspace/node-src"}
devcontainer exec --workspace-folder ./ --config .devcontainer/node-container/devcontainer.json node hello.js
Hello World
devcontainer exec --workspace-folder ./ --config .devcontainer/python-container/devcontainer.json python hello.py
[114 ms] Error: Dev container not found. at Ka (/Users/user/.nvm/versions/node/v22.13.1/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:471:768) at tl (/Users/user/.nvm/versions/node/v22.13.1/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:668:6034) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async OrA (/Users/user/.nvm/versions/node/v22.13.1/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:668:3703) at async /Users/user/.nvm/versions/node/v22.13.1/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:482:1190
@JustinCoded The compose project name is the same for both dev containers, this is likely the cause of the problem because Docker Compose does not distinguish between the two and ends up spawning only the first. Could you try using different project names?
The original ask in this issue seems to have been fixed with https://github.com/devcontainers/ci/issues/212.