visual-studio-codevscode-devcontainerdevcontainer

How can I specify a devcontainer feature more than once?


I'm building a custom devcontainers file and need to add a couple of homebrew packages. In the features list, there's a homebrew-package that does the job. The only problem is, this only accepts one package (there's a similar pipx-package feature which has the same format/problem).

How can I specify this feature multiple times so that I can install multiple homebrew packages? The best I can think of is repeating the declaration, but that doesn't work for obvious reasons.

{
  "features": {
    "ghcr.io/devcontainers-contrib/features/homebrew-package:1": {
      "package": "detect-secrets"
    },
    "ghcr.io/devcontainers-contrib/features/homebrew-package:1": {
      "package": "markdownlint-cli"
    }
  }
}

Solution

  • tl;dr - this cannot be done.

    If you want to do this, you need to create a local custom feature. This can be solved fairly elegantly by calling the package via a bash script.

    As an example, the neovim-homebrew package demonstrates how to call a package from another package via the Dev Containers CLI