我正在使用
VS Code
并安装了 Remote Development
扩展。我为我的 Angular 应用程序创建了一个 devcontainer
。到目前为止,一切正常。 Dockerfile 和 devcontainer.json 文件非常简单:
Dockerfile:
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-12
devcontainer.json:
{
"name": "Angular App",
"dockerFile": "Dockerfile",
"settings": {
"git.path": "/usr/bin/git",
"terminal.integrated.shell.linux": "/bin/bash"
},
"extensions": [
"angular.ng-template",
"natewallace.angular2-inline",
"dbaeumer.vscode-eslint"
],
"forwardPorts": [4200, 9876],
"mounts": [ ],
"remoteEnv": { },
"postCreateCommand": "yarn install",
}
在我的容器之外,我的 git 路径位于 C:\Program Files\... 目录中。在我的容器中,git 路径是 /usr/bin/git,这就是我设置
"git.path"
属性的原因,并且我通过在容器内使用 which git
命令来验证这一点。当然,所有 git 命令都不起作用,因为它们总是会导致错误。
致命:无法 chdir 到“C:/Workspace/my-angular-app”:没有这样的文件 或目录
我总是可以使用
Remote-Containers: Reopen Locally
命令,一旦我回到 Windows(在容器之外),我的源代码管理器就会亮起我的所有差异,并且 git 工作得很好。但是,如果有一种方法可以让 git 在容器内工作,那将会很有帮助。我不想在进行更改时不断退出容器来识别差异。
此问题已解决,但最初是 Docker 问题:https://github.com/microsoft/vscode-remote-release/issues/2591
您可能还需要将 Windows 样式路径更改为 *nix 样式路径。在这种情况下,请尝试 /mnt/c/Workspace...而不是 C:/Workspace...
我最近一直在尝试找到此问题的解决方案,我的结论是使用具有功能或脚本的不同基础映像来安装 Node、npm 等,而不是专门为 Node 制作的基础映像。
似乎在尝试专门为节点创建某些东西时,由于 Dockerfile 映像的构建方式而导致权限被破坏。
TL:博士;
✅
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-20.04",
"features": {
"ghcr.io/devcontainers/features/node": "latest",
"ghcr.io/devcontainers-contrib/features/npm-package": "latest",
❌ 不是
mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye
mcr.microsoft.com/devcontainers/typescript-node
图像的问题示例
鉴于此图像来自官方“devcontainer”注册表而不是第 3 方,并且预计质量更高,看到这些问题令人惊讶。希望他们能解决这个问题。