在VS Code Remote Container扩展创建的容器中未检测到Git存储库

g6baxovj  于 11个月前  发布在  Git
关注(0)|答案(2)|浏览(120)

描述问题

因此,我正在使用VS Code Remote Container扩展来设置我的应用程序开发环境。
我可以设置它的好,它是工作得很好!但是,它似乎不能检测到的git repo内的容器?
所以,我认为,它没有检测到git repo的原因是git config中的worktree仍然指向我的主机路径。
x1c 0d1x的数据



那么,我可以做些什么来使工作树动态地变为指向容器内的路径呢?我在谷歌上搜索了这个问题,但没有成功。

配置

下面是我的设置


设备容器.json

{
  "name": "foobar-dev-env",
  "dockerComposeFile": "docker-compose.yml",
  "extensions": [
    // Git
    "github.vscode-pull-request-github",
    "eamodio.gitlens",
    "mhutchie.git-graph",

    // Code
    "coenraads.bracket-pair-colorizer-2",
    "aaron-bond.better-comments",
    "streetsidesoftware.code-spell-checker",
    "alefragnani.numbered-bookmarks",
    "pflannery.vscode-versionlens",
    "visualstudioexptteam.vscodeintellicode",
    "redhat.vscode-yaml", // YAML
    "kumar-harsh.graphql-for-vscode", // GraphQL

    // Prettier
    "esbenp.prettier-vscode",

    // Todo
    "gruntfuggly.todo-tree",
    "wayou.vscode-todo-highlight",

    // Theme
    "pkief.material-icon-theme",
    "zhuangtongfa.material-theme"
  ],
  "settings": {
    "workbench.colorTheme": "One Dark Pro",
    "workbench.iconTheme": "material-icon-theme",
    "workbench.sideBar.location": "right",

    "oneDarkPro.editorTheme": "Onedark Pro",
    "oneDarkPro.bold": true,
    "oneDarkPro.vivid": true,
    "oneDarkPro.italic": false,

    "editor.minimap.enabled": false,
    "editor.tabSize": 2,
    "editor.wordWrapColumn": 120,
    "editor.rulers": [120],
    "editor.formatOnSave": true,

    "[typescript, javascript]": {
      "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "typescript.updateImportsOnFileMove.enabled": "always",
    "javascript.updateImportsOnFileMove.enabled": "always",

    "terminal.integrated.shell.linux": "/bin/bash"
  },
  "service": "app",
  "workspaceFolder": "/workspace",
  "shutdownAction": "stopCompose"
}

字符串

码头撰写.yml

version: "3.3"

services:
  app-db:
    image: postgres:12
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_DB: app_db
      POSTGRES_PASSWORD: secret
    ports:
      - 54321:5432
    volumes:
      - app-db-data:/var/lib/postgresql/data

  app:
    image: node:12-stretch
    restart: always
    depends_on:
      - app-db
    command: /bin/sh -c "while sleep 1000; do :; done"
    ports:
      - 4000:4000
    volumes:
      # Mounts the project folder to '/workspace'. The target path inside the container
      # should match what your application expects. In this case, the compose file is
      # in a sub-folder, so we will mount '..'. You would then reference this path as the
      # 'workspaceFolder' in '.devcontainer/devcontainer.json' so VS Code starts here.
      - ..:/workspace:cached

volumes:
  app-db-data:


先谢了。

备注

我之所以在docker-compose.yml文件中的image上使用node:12-stretch,是因为如果我使用node:12-alpine,它没有安装git,所以现在VS代码会抱怨没有安装git。
node:12-stretch图像中已预先安装git



如果可以的话,我希望使用node:12-alpine tho,因为我想模仿这个dev env将要部署的prodenv。希望你们也能帮助我。
干杯

环境

  • Docker桌面版本2.3.0.3(使用基于WSL 2的引擎)
  • Windows 10专业版2004
byqmnocz

byqmnocz1#

今天我在我的设置中偶然发现了同样的问题:

  • Windows Docker Desktop与WSL 2集成
  • VS Code Dev容器与Dockerfile

正如你提到的,在仓库内的git配置文件中有一个绝对的win路径,这会导致容器内的rep失败。
我的解决方法是,使这个路径相对,所以源代码控制现在在docker容器内工作。
下面是我的配置:

.git/config

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    worktree = ../
    symlinks = false
    ignorecase = true

字符串

设备容器.json

{
    "name": "Tensorflow GPU",
    "dockerFile": "Dockerfile",
    "settings": {
        "git.path": "/usr/bin/git"
    },
    "extensions": [
        "ms-python.python"
    ]
}

Dockerfile

FROM tensorflow/tensorflow:latest-gpu
RUN apt-get update && apt-get install -y git


PS:不幸的是,使用这种方法,本地存储库会被吓坏,并希望您在离开容器后提交所有文件

acruukt9

acruukt92#

只需从.git/config文件中删除worktree属性即可。
重新构建容器,git应该可以正常工作。用git status检查。

相关问题