visual-studio-codedocker-composevscode-devcontainer

Attach to a container + auto install plugins


I'm having an issue to setup correctly my project. I have a docker-compose, that I must launch using a custom bash function to create some files and setup the environment. When the containers are running, I can now attach to one of them named "dnode", which contains the code and all the necessary tools.

At this point, my project works. But my problem is I would like to define a file that indicate to vscode to automaticly install some extensions. I tried the .devcontainer.json but it seems to be more related to "create a devcontainer" than "attach to an existing container". I don't want vscode to make it's own container, but still need it to install automaticly.

Is there a way to achieve this ? I get an error if i try to open the json file since it does not specify an image to use.

Thanks !


Solution

  • There is no VS Code setting or configuration that allows automatic installation of extension. There is however the possibility to recommend extensions, on a workspace/folder level, and VS Code will display a notification about it.

    To accomplish this, create a file .vscode/extensions.json with something like this:

    {
      "recommendations": [
        "ms-python.python",
        "esbenp.prettier-vscode",
        "dbaeumer.vscode-eslint"
      ]
    }
    

    On the other hand, if you are dealing with docker-compose, you could use the VS Code CLI and install the extensions via shell, using the --install-extension arg. More details in https://code.visualstudio.com/docs/editor/command-line#_working-with-extensions