1

Is it possible in the dev container specification to specify one or more terminals to be opened as part of the dev container?

My use case is that I'd like to open two terminals for the user:

  1. Build and host the app.
  2. Build and run the app API.

The idea is simply to save the user's time of having to open up the terminals themselves and run the relevant commands.

Chris Talman
  • 1,059
  • 2
  • 14
  • 24

1 Answers1

1

Same terminal

If you don't need the logs in separate terminals, you can use the postStartCommand lifecycle script.

Add your commands to the devcontainer.json file, with the commands separated by &&; use nohup as in this example to leave the processes running:

"postStartCommand": "echo hello && echo world"

Separate terminals

If you want separate terminals, you can create a custom task; the page also contains info on how to further customize your tasks.

// .vscode/tasks.json
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build Host",
            "type": "shell",
            "command": "echo hello",
            "group": "build",
            "presentation": {
                "group": "buildGroup",
                "reveal": "always",
                "panel": "new",
                "echo": false,
            }
        },
        {
            "label": "Build API",
            "type": "shell",
            "command": "echo world",
            "group": "build",
            "presentation": {
                "group": "buildGroup",
                "reveal": "always",
                "panel": "new",
                "echo": false,
            }
        },
        {
            "label": "Build All",
            "dependsOn": [
                "Build Host",
                "Build API"
            ],
            "group": "build",
            "runOptions": {
                "runOn": "folderOpen" // This starts both tasks when the container is started
            },
        }
    ]
}

With Run and Debug

Finally, depending on what project your are working on, you can use the launch.json file to set a custom run command. Here you can find the documentation.

Giubots
  • 134
  • 1
  • 5