vscode devcontainer不再生成:rpc错误:找不到代码=未知desc=目标阶段dev_container



我一直在一个devcontainer中进行C++开发,我重建了容器,但它未能构建。此后,我尝试了另一个容器,但它也无法构建。我知道devcontainer文件和dockerfile与工作时没有变化。

当我第一次注意到我在一个类似的repo上打开了另一个devcontainer时,它很好地启动了容器。当我试图重建它时,我也遇到了同样的错误。

第一个错误是

错误:无法解决:rpc错误:code=未知desc=无法使用前端dockerfile.v0:无法使用前端网关解决.v0:rpc错误;code=未知desc=找不到目标阶段dev_containers_target_stage

上下文

=> CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531b  0.0s
[2022-10-07T21:44:13.502Z] [+] Building 1.8s (7/7) FINISHED                                                
=> [internal] load build definition from Dockerfile-with-features         0.0s
=> => transferring dockerfile: 1.12kB                                     0.0s
=> [internal] load .dockerignore                                          0.0s
=> => transferring context: 2B                                            0.0s
=> resolve image config for docker.io/docker/dockerfile:1.4               1.5s
[2022-10-07T21:44:13.502Z]  => [auth] docker/dockerfile:pull token for registry-1.docker.io           0.0s
=> CACHED docker-image://docker.io/docker/dockerfile:1.4@sha256:9ba7531b  0.0s
=> [internal] load build definition from Dockerfile-with-features         0.0s
=> [internal] load .dockerignore                                          0.0s
ERROR: failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = target stage dev_containers_target_stage could not be found
[2022-10-07T21:44:13.511Z] Stop (2075 ms): Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-david/container-features/0.19.0-1665179051412/Dockerfile-with-features -t vsc-components-e3528559c8b219e2efe0f837299d4fa8 --target dev_containers_target_stage --build-context dev_containers_feature_content_source=/tmp/devcontainercli-david/container-features/0.19.0-1665179051412 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /home/david/Repos/Arabica/Components/.devcontainer
[2022-10-07T21:44:13.512Z] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-david/container-features/0.19.0-1665179051412/Dockerfile-with-features -t vsc-components-e3528559c8b219e2efe0f837299d4fa8 --target dev_containers_target_stage --build-context dev_containers_feature_content_source=/tmp/devcontainercli-david/container-features/0.19.0-1665179051412 --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label --build-arg _DEV_CONTAINERS_IMAGE_USER=root --build-arg _DEV_CONTAINERS_FEATURE_CONTENT_SOURCE=dev_container_feature_content_temp /home/david/Repos/Arabica/Components/.devcontainer
[2022-10-07T21:44:13.512Z]     at fD (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:298:1633)
[2022-10-07T21:44:13.513Z]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[2022-10-07T21:44:13.513Z]     at async wd (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:297:1958)
[2022-10-07T21:44:13.513Z]     at async sC (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:297:894)
[2022-10-07T21:44:13.513Z]     at async bD (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:303:2020)
[2022-10-07T21:44:13.513Z]     at async ys (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:303:3182)
[2022-10-07T21:44:13.513Z]     at async UL (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:423:10319)
[2022-10-07T21:44:13.513Z]     at async ML (/home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js:423:10075)
[2022-10-07T21:44:13.515Z] Stop (3813 ms): Run in Host: /home/david/.vscode-server/bin/64bbfbf67ada9953918d72e1df2f4d8e537d340e/node /home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js up --workspace-folder /home/david/Repos/Arabica/Components --workspace-mount-consistency cached --id-label devcontainer.local_folder=\wsl.localhostUbuntuhomedavidReposArabicaComponents --log-level debug --log-format json --config /home/david/Repos/Arabica/Components/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-10-07T21:44:13.515Z] Exit code 1
[2022-10-07T21:44:13.518Z] Command failed: /home/david/.vscode-server/bin/64bbfbf67ada9953918d72e1df2f4d8e537d340e/node /home/david/.vscode-remote-containers/dist/dev-containers-cli-0.255.2/dist/spec-node/devContainersSpecCLI.js up --workspace-folder /home/david/Repos/Arabica/Components --workspace-mount-consistency cached --id-label devcontainer.local_folder=\wsl.localhostUbuntuhomedavidReposArabicaComponents --log-level debug --log-format json --config /home/david/Repos/Arabica/Components/.devcontainer/devcontainer.json --default-user-env-probe loginInteractiveShell --remove-existing-container --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-10-07T21:44:13.518Z] Exit code 1

供参考的devcontainer是

// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/cpp
{
"name": "Components",
"build": {
"dockerfile": "Dockerfile"
},
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspace,type=bind,consistency=cached",
"workspaceFolder": "/workspace/Components",
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"ms-vscode.cpptools-themes",
"ms-vscode.makefile-tools",
"jeff-hykin.better-cpp-syntax",
"bneumann.cpputest-test-adapter"
]
}
},
// Use 'postCreateCommand' to run commands after the container is created. "postStartCommand": "git config --global core.sshCommand /usr/bin/ssh",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}

Dockerfile

FROM davidcozens/cpputest:4
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Create the user
RUN groupadd --gid $USER_GID $USERNAME 
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME 

到目前为止,我已经尝试过:擦除docker缓存的图像并清理容器。我已经在wsl2中更新了我的ubuntu发行版,我已经确保docker是最新的。我已经更新了windows-我正在运行最新版本的windows 11。

问题是Dockerfile:的最后一行

# Create the user
RUN groupadd --gid $USER_GID $USERNAME 
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME 

Docker以前可能支持DockerfileRUN语句中的最后一个尾部斜杠,但现在似乎不再支持它了。(我不确定这是什么时候发生的,但我在Docker 20.10.21上,它不再受支持。(

这个尾随斜杠似乎干扰了VS代码生成的Dockerfile-with-features文件中的以下FROM语句,该文件看起来如下:

# Create the user
RUN groupadd --gid $USER_GID $USERNAME 
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME 

FROM $_DEV_CONTAINERS_BASE_IMAGE AS dev_containers_target_stage

如果FROM语句不再能够被读取,那么错误消息就更有意义了:

找不到目标阶段dev_containers_target_stage

删除Dockerfile中的尾部,它应该可以工作。

相关内容

  • 没有找到相关文章

最新更新