首页 > 解决方案 > 无法使用远程容器将 C/C++ 扩展安装到 VisualCode

问题描述

我无法使用“远程 - 容器”在开发容器中安装扩展。我想从现有的 docker 文件在容器中开发一些 C 应用程序。为此我设置了一个.devcontainer.json

{
    "name": "Jenkins_virtual_env",

    "dockerFile":"../container/Dockerfile",
    // Use this environment variable if you need to bind mount your local source code into a new container.
    "remoteEnv": {
        "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
    },

    "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],


    // 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": [
        "ms-vscode.cpptools",
        "ms-vscode.cpptools-extension-pack"
    ],
    
    // 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": "docker --version",

    // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
    //"remoteUser": "vscode"
}

现在在“ReOpen in Container”之后,容器启动,我可以在这个容器中执行命令。但是,当启动安装扩展时,会显示错误。

Updating C/C++ dependencies...

Downloading package 'C/C++ language components (Linux / x86_64)'  Failed. Retrying... Failed. Retrying... Failed. Retrying...Waiting 8 seconds... Failed. Retrying...Waiting 16 seconds... Failed to download https://go.microsoft.com/fwlink/?linkid=2155055
Failed at stage: downloadPackages
Error: connect ECONNREFUSED 127.0.0.1:9000
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)

If you work in an offline environment or repeatedly see this error, try downloading a version of the extension with all the dependencies pre-included from https://github.com/microsoft/vscode-cpptools/releases, then use the "Install from VSIX" command in VS Code to install it.

我不确定谁想要连接到 localhost:9000 但我猜它是容器内的一个应用程序。我看到的是,容器中似乎有一个端口转发处于活动状态

关于设置的一些事实:

我已经检查了什么:为了避免在我的 dockerfile 中排除错误,我回到了 microsoft 默认 c++ 映像(https://github.com/microsoft/vscode-remote-try-cpp)。我还检查了主机系统上使用的端口。我发现,端口 9000 已被 zscaler 使用。但是 Code.exe 正在侦听端口 9001(适合转发的 docker 端口)。

我还使用了 中的“appPort”选项.devcontainer.json,唯一的效果是,我在容器和主机之间看到了一个额外的隧道。错误消息保持不变。

有没有人对此有想法,或者可能有一些提示如何进行更深入的调查?我不知道哪个组件导致了这个问题('C/C++ 扩展'或'远程容器'或'VCS'本身......或一些隐藏的组件)。

标签: windowsdockervisual-studio-code

解决方案


推荐阅读