首页 > 解决方案 > vscode-remote-container 在 post*Command 后打开用户终端

问题描述

如果你运行 apost*Command你会得到一个运行命令和输出的集成终端:

从 devcontainer.json 运行 PostCreateCommand...

[2709 毫秒] 开始:在容器中运行:...

完毕。按任意键关闭终端。

有没有办法让这个自动关闭并打开一个用户终端,或者只是离开它并打开一个用户终端,就好像你根本没有运行任何命令一样devcontainer.json

标签: dockervisual-studio-codeterminalcontainers

解决方案


使用涉及 Python 的示例,您可以尝试使用postAttachCommand

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

这使:

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#

描述postCreateCommand如下:

创建容器后要运行的命令。此命令在 "updateContentCommand" 之后和"postStartCommand" 之前运行。

而描述postAttachCommand指定:

附加到容器时运行的命令。此命令在“postStartCommand”之后运行。

所以其他变化可能是可能的,但这个对我有用。


推荐阅读