Ubuntu下VSCode无法构建/打开Devcontainer:Docker Build时lstat失败
Dev Container启动失败(文件不存在报错)的排查方案
问题场景
- 环境:Ubuntu 24.04.1 LTS、Docker 27.2.0(build 3ab4256)、VSCode Remote Containers插件0.394.0
- 现象:打开多个不同仓库的Dev Container均失败,核心报错为
ERROR: resolve : lstat /tmp/devcontainercli-<USERNAME>: no such file or directory
完整报错信息
mcr.microsoft.com/vscode/devcontainers/java:11 [6654 ms] Start: Run: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-<USERNAME>/container-features/0.72.0-1734105891999/Dockerfile-with-features -t vsc-sample-dd36907828f3213d85a1bc1c5a049f9547307b19b12650f341b623807eb5e56e --target dev_containers_target_stage --build-arg VARIANT=11 --build-arg INSTALL_MAVEN=false --build-arg INSTALL_GRADLE=false --build-arg INSTALL_NODE=false --build-arg NODE_VERSION=lts/* --build-arg INSTALL_SBT=true --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label /home/<USERNAME>/devcontainers/vscode-dev-containers-scala-sbt/sample/.devcontainer [+] Building 0.0s (0/0) docker:default ERROR: resolve : lstat /tmp/devcontainercli-<USERNAME>: no such file or directory [7562 ms] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-<USERNAME>/container-features/0.72.0-1734105891999/Dockerfile-with-features -t vsc-sample-dd36907828f3213d85a1bc1c5a049f9547307b19b12650f341b623807eb5e56e --target dev_containers_target_stage --build-arg VARIANT=11 --build-arg INSTALL_MAVEN=false --build-arg INSTALL_GRADLE=false --build-arg INSTALL_NODE=false --build-arg NODE_VERSION=lts/* --build-arg INSTALL_SBT=true --build-arg _DEV_CONTAINERS_BASE_IMAGE=dev_container_auto_added_stage_label /home/<USERNAME>/devcontainers/vscode-dev-containers-scala-sbt/sample/.devcontainer [7562 ms] at RtA (/home/<USERNAME>/.vscode/extensions/ms-vscode-remote.remote-containers-0.394.0/dist/spec-node/devContainersSpecCLI.js:466:1933) [7562 ms] at async _m (/home/<USERNAME>/.vscode/extensions/ms-vscode-remote.remote-containers-0.394.0/dist/spec-node/devContainersSpecCLI.js:465:1896) [7563 ms] at async bH (/home/<USERNAME>/.vscode/extensions/ms-vscode-remote.remote-containers-0.394.0/dist/spec-node/devContainersSpecCLI.js:465:610) [7563 ms] at async TtA (/home/<USERNAME>/.vscode/extensions/ms-vscode-remote.remote-containers-0.394.0/dist/spec-node/devContainersSpecCLI.js:482:3848) [7563 ms] at async iB (/home/<USERNAME>/.vscode/extensions/ms-vscode-remote.remote-containers-0.394.0/dist/spec-node/devContainersSpecCLI.js:482:4963) [7563 ms] at async wrA (/home/<USERNAME>/.vscode/extensions/ms-vscode-remote.remote-containers-0.394.0/dist/spec-node/devContainersSpecCLI.js:663:203) [7563 ms] at async DrA (/home/<USERNAME>/.vscode/extensions/ms-vscode-remote.remote-containers-0.394.0/dist/spec-node/devContainersSpecCLI.js:662:14830) [7563 ms] at async /home/<USERNAME>/.vscode/extensions/ms-vscode-remote.remote-containers-0.394.0/dist/spec-node/devContainersSpecCLI.js:482:1190 [7572 ms] Exit code 1 [7584 ms] Command failed: /usr/share/code/code /home/<USERNAME>/.vscode/extensions/ms-vscode-remote.remote-containers-0.394.0/dist/spec-node/devContainersSpecCLI.js up --user-data-folder /home/<USERNAME>/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/data --container-session-data-folder /tmp/devcontainers-41c979f9-ad0d-41be-b094-a32fe3da171d1734105883116 --workspace-folder /home/<USERNAME>/devcontainers/vscode-dev-containers-scala-sbt/sample --workspace-mount-consistency cached --gpu-availability detect --id-label devcontainer.local_folder=/home/<USERNAME>/devcontainers/vscode-dev-containers-scala-sbt/sample --id-label devcontainer.config_file=/home/<USERNAME>/devcontainers/vscode-dev-containers-scala-sbt/sample/.devcontainer/devcontainer.json --log-level debug --log-format json --config /home/<USERNAME>/devcontainers/vscode-dev-containers-scala-sbt/sample/.devcontainer/devcontainer.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 --include-configuration --include-merged-configuration [7585 ms] Exit code 1
可能的原因及解决方法
- 临时目录权限或自动清理问题
- 检查
/tmp目录权限:执行ls -ld /tmp,确认权限为drwxrwxrwt,确保当前用户有读写权限 - 排查系统自动清理机制:查看
/usr/lib/tmpfiles.d/tmp.conf,确认临时文件留存时间是否过短;若存在定时清理任务,可临时禁用后重试
- 检查
- Docker与插件版本兼容性冲突
- Docker 27.x属于较新版本,可能和Remote Containers插件0.394.0存在兼容问题,可尝试降级Docker到26.x稳定版,或升级Remote Containers插件至最新版本
- 用户名包含特殊字符
- 执行
whoami检查用户名,若包含空格、非ASCII字符等特殊符号,可能导致插件生成临时路径时解析错误,建议使用仅含字母、数字、下划线的用户名
- 执行
- 插件缓存或临时文件异常
- 关闭VSCode,删除以下目录后重启重试:
~/.config/Code/User/globalStorage/ms-vscode-remote.remote-containers/tmp下所有以devcontainercli-或devcontainers-开头的文件夹
- 关闭VSCode,删除以下目录后重启重试:
内容的提问来源于stack exchange,提问作者Alexandr Savochkin
相关产品推荐
相关产品推荐

