我尝试运行devcontainer。设置文件:
devcontainer.json
{
"name": "C++",
"build": {
"dockerfile": "Dockerfile"
},
"features": {
"ghcr.io/devcontainers/features/git:1": {}
}
}
Dockerfile
FROM mcr.microsoft.com/devcontainers/cpp:0-debian-11
ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="3.22.2"
# Optionally install the cmake for vcpkg
COPY ./reinstall-cmake.sh /tmp/
RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE};
fi
&& rm -f /tmp/reinstall-cmake.sh
但是当我尝试运行devcontainer时,我得到错误:
[2022-12-23T18:57:44.771Z] ERROR: invalid character 'x00' looking for beginning of value
[2022-12-23T18:57:44.863Z] Stop (969 ms): Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f C:UsersBOGUS_~1.NEWAppDataLocalTempdevcontainerclicontainer-features .25.2-1671821861765Dockerfile-with-features -t vsc-test-9da7bcb89243449acfae569e26bf0e4b --target dev_containers_target_stage --build-context dev_containers_feature_content_source=C:UsersBOGUS_~1.NEWAppDataLocalTempdevcontainerclicontainer-features .25.2-1671821861765 --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 c:Projectsdocker_projectsCpptest.devcontainer
[2022-12-23T18:57:44.865Z] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f C:UsersBOGUS_~1.NEWAppDataLocalTempdevcontainerclicontainer-features .25.2-1671821861765Dockerfile-with-features -t vsc-test-9da7bcb89243449acfae569e26bf0e4b --target dev_containers_target_stage --build-context dev_containers_feature_content_source=C:UsersBOGUS_~1.NEWAppDataLocalTempdevcontainerclicontainer-features .25.2-1671821861765 --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 c:Projectsdocker_projectsCpptest.devcontainer
[2022-12-23T18:57:44.866Z] at Doe (c:UsersBogus_Kladik.NEW-PC.vscodeextensionsms-vscode-remote.remote-containers-0.266.1distspec-nodedevContainersSpecCLI.js:1894:1669)
[2022-12-23T18:57:44.866Z] at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
[2022-12-23T18:57:44.866Z] at async EF (c:UsersBogus_Kladik.NEW-PC.vscodeextensionsms-vscode-remote.remote-containers-0.266.1distspec-nodedevContainersSpecCLI.js:1893:1978)
[2022-12-23T18:57:44.866Z] at async uT (c:UsersBogus_Kladik.NEW-PC.vscodeextensionsms-vscode-remote.remote-containers-0.266.1distspec-nodedevContainersSpecCLI.js:1893:901)
[2022-12-23T18:57:44.866Z] at async Poe (c:UsersBogus_Kladik.NEW-PC.vscodeextensionsms-vscode-remote.remote-containers-0.266.1distspec-nodedevContainersSpecCLI.js:1899:2128)
[2022-12-23T18:57:44.867Z] at async Zf (c:UsersBogus_Kladik.NEW-PC.vscodeextensionsms-vscode-remote.remote-containers-0.266.1distspec-nodedevContainersSpecCLI.js:1899:3278)
[2022-12-23T18:57:44.867Z] at async aue (c:UsersBogus_Kladik.NEW-PC.vscodeextensionsms-vscode-remote.remote-containers-0.266.1distspec-nodedevContainersSpecCLI.js:2020:15276)
[2022-12-23T18:57:44.867Z] at async oue (c:UsersBogus_Kladik.NEW-PC.vscodeextensionsms-vscode-remote.remote-containers-0.266.1distspec-nodedevContainersSpecCLI.js:2020:15030)
[2022-12-23T18:57:44.882Z] Stop (5862 ms): Run: C:UsersBogus_Kladik.NEW-PCAppDataLocalProgramsMicrosoft VS CodeCode.exe --ms-enable-electron-run-as-node c:UsersBogus_Kladik.NEW-PC.vscodeextensionsms-vscode-remote.remote-containers-0.266.1distspec-nodedevContainersSpecCLI.js up --user-data-folder c:UsersBogus_Kladik.NEW-PCAppDataRoamingCodeUserglobalStoragems-vscode-remote.remote-containersdata --workspace-folder c:Projectsdocker_projectsCpptest --workspace-mount-consistency cached --id-label devcontainer.local_folder=c:Projectsdocker_projectsCpptest --log-level debug --log-format json --config c:Projectsdocker_projectsCpptest.devcontainerdevcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-12-23T18:57:44.882Z] Exit code 1
[2022-12-23T18:57:44.889Z] Command failed: C:UsersBogus_Kladik.NEW-PCAppDataLocalProgramsMicrosoft VS CodeCode.exe --ms-enable-electron-run-as-node c:UsersBogus_Kladik.NEW-PC.vscodeextensionsms-vscode-remote.remote-containers-0.266.1distspec-nodedevContainersSpecCLI.js up --user-data-folder c:UsersBogus_Kladik.NEW-PCAppDataRoamingCodeUserglobalStoragems-vscode-remote.remote-containersdata --workspace-folder c:Projectsdocker_projectsCpptest --workspace-mount-consistency cached --id-label devcontainer.local_folder=c:Projectsdocker_projectsCpptest --log-level debug --log-format json --config c:Projectsdocker_projectsCpptest.devcontainerdevcontainer.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default on --mount-workspace-git-root true
[2022-12-23T18:57:44.889Z] Exit code 1
如何解决这个问题?
在这些尝试中,我可以注意到Docker Desktop的更新,wsl的更新这个问题似乎与Docker中使用BuildKit和内联缓存有关。
这里建议的解决方法是:
-
在Docker中禁用BuildKit:
-
在Linux下:
# in /etc/bash.bashrc export DOCKER_BUILDKIT=0
-
Docker Dashboard下:
进入设置>Docker引擎并设置'buildkit'为'false':
"features": { "buildkit": false },
-
-
禁用内联缓存:
-
Dockerfile:
"args": { "BUILDKIT_INLINE_CACHE": "0" }
-
在devcontainer.json:
"build": { "dockerfile": "Dockerfile", "args": { "BUILDKIT_INLINE_CACHE": "0" } },
-
在docker- composer .yml:
services: app: build: context: . dockerfile: Dockerfile args: BUILDKIT_INLINE_CACHE: 0
-