skip to Main Content

When I use the "Attach to Running Container…" feature of VS Code I have to manually install the few extensions that I need installed in the container.

Attach to Running Container...

Is there a way to setup VS Code such that when I attach to a running container it automatically installs the extensions I need?

I am aware of this question: Automatically install extensions in VS Code?

But that doesn’t say anything about installing extensions in running containers automatically and isn’t clear on how the answers could be used to accomplish this.

The specific extension I need installed is the Python extension from Microsoft. I’m not sure that is relevant, but just in case it is.

2

Answers


  1. From a similar question on Github:

    You can add an array of extension ids to the ‘attach’ configuration ("extensions" property). Use F1 > Remote-Containers: Open Attached Container Configuration File… to open that. Note that for each container extensions will be installed only the first time you attach to it, changes to "extensions" in the config file after that will only apply to the next container with the same image name (or container name, if the config is scoped to that).

    Login or Signup to reply.
  2. Not sure when this feature was added, but in VSCode, open your project in the remote container as normal, then under the extensions side-tab, find the extension you want and click the "cog" settings icon. It has the open to "Add to devcontainer.json".

    enter image description here

    This command will add that extension to the customizations.vscode.extensions setting in the devcontainer.json file.

    {
        "name": "MyContainer",
        // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
        "dockerComposeFile": "docker-compose.yml",
        "service": "devcontainer",
        "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
        "customizations": {
            "vscode": {
                "extensions": [
                    # added by VSCode
                    "ms-python.python"
                ]
            }
        },
        ...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search