vscode-remote-container open user terminal after post*Command

Viewed 517

if you run a post*Command you get an integrated terminal that runs the command(s) and outputs:

Running the PostCreateCommand from devcontainer.json...

[2709 ms] Start: Run in container: ...

Done. Press any key to close the terminal.

is there a way to have this auto close and open a user terminal or just leave it and open a user terminal as if you werent running any commands from devcontainer.json at all?

1 Answers

Using an example involving Python, you can try using postAttachCommand:

{
    "postCreateCommand": ["poetry", "install"],
    "postAttachCommand": "bash"
}

which gives:

Running the postCreateCommand from devcontainer.json...

[28000 ms] Start: Run in container: poetry install
Installing dependencies from lock file

No dependencies to install or update

Installing the current project: project (0.1.0)

Running the postAttachCommand from devcontainer.json...

[33815 ms] Start: Run in container: /bin/sh -c bash
root@a0fd27a3b2cc:/workspaces/directory#

The description for postCreateCommand reads:

A command to run after creating the container. This command is run after "updateContentCommand" and before "postStartCommand".

whereas the description for postAttachCommand specifies:

A command to run when attaching to the container. This command is run after "postStartCommand".

So other variations might be possible, but this one worked for me.

Related