📝 Windows + Docker + VS Code Remote-Containers 故障排查与恢复

📝 Windows + Docker + VS Code Remote-Containers 故障排查与恢复#

1️⃣ 背景问题#

常见报错:

  • remote-containers.explorerTargetsRefresh: stream is closed

  • An error occurred attaching to the container

  • Unable to read file '…package.json'

原因一般为:

  1. Docker context 错误(VS Code 连接到错误 Docker 引擎)

  2. Remote-Containers / Dev Containers 扩展损坏或缓存残留

  3. VS Code 内部缓存或 workspaceStorage 被锁

  4. 容器本身缺 shell 或 ENTRYPOINT 阻塞(本次案例排除)


2️⃣ 排查 Docker Context#

docker context ls
  • 正确 context 应该指向 Windows Docker 引擎:
default *
  • 如果 context 是 desktop-linux,切换回默认:
docker context use default
  • 验证容器可访问:
docker ps
docker exec -it <container> sh
docker exec -it <container> bash

✅ 能进入容器说明容器正常。