Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code in docker container: Is there a way to automatically install extensions when connecting to a running container?

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.

like image 678
chadgh Avatar asked Sep 10 '25 19:09

chadgh


1 Answers

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"
            ]
        }
    },
    ...
like image 164
glycoaddict Avatar answered Sep 13 '25 04:09

glycoaddict