如何从正在运行的容器中分离VSCode?

时间:2019-05-16 09:57:02

标签: visual-studio-code vscode-remote

这可能是有史以来最愚蠢的问题,但是我找不到一种简单的方法。

我已成功将VSCode附加到计算机中正在运行的容器中。但是现在,每次我打开VSCode时,它都会自动附加到该容器上。有什么办法可以分离它并只打开VSCode吗?

编辑:如您所见,每次打开VSCode内部人员时,它都会自动附加到正在运行的容器中。如果容器停止,它甚至会启动容器

enter image description here

这是我尝试运行与远程容器关联的命令时看到的菜单。我已附加到正在运行的docker容器,并且如果未附加该容器,则无法重新打开该文件夹。

No reopen folder unattached to running container

是的,我正在使用Remote Development Extension Pack + VSCode Insiders 1.35

这些是我计算机上的VSCode Remote,Node和其他相关软件组件的版本

enter image description here

那么,我如何从该容器中分离VSCode内部人员而不删除容器+图像?

2 个答案:

答案 0 :(得分:0)

也许您正在寻找命令Remote-Containers: Reopen Folder Locally

答案 1 :(得分:0)

执行此操作的方法是关闭工作空间文件夹-这将完全分离正在运行的容器并关闭现有项目。

下一步是重新打开本地源代码文件夹。 有文件夹调用.devcontainer-包含 devcontainer.json 文件-

// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.122.1/containers/ubuntu
{
    "name": "Ubuntu",
    "build": {
        "dockerfile": "Dockerfile",
        // Update 'VARIANT' to pick an Ubuntu version. Rebuild the container 
        // if it already exists to update. Available variants: 18.04, 20.04
        "args": { "VARIANT": "18.04" }
    },

    // Set *default* container specific settings.json values on container create.
    "settings": { 
        "terminal.integrated.shell.linux": "/bin/bash"
    },

    // Add the IDs of extensions you want installed when the container is created.
    "extensions": []

    // Use 'forwardPorts' to make a list of ports inside the container available locally.
    // "forwardPorts": [],

    // Use 'postCreateCommand' to run commands after the container is created.
    // "postCreateCommand": "uname -a",

    // Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker.
    // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],

    // Uncomment when using a ptrace-based debugger like C++, Go, and Rust
    // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

    // Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
    // "remoteUser": "vscode"
}

删除它还会分离一个正在运行的容器-您甚至可以将docker容器修改为所需的容器,然后重新构建。