Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get git to work properly from within a dev container using VS Code?

I am working with VS Code and I installed the Remote Development extension. I created a devcontainer for my Angular application. So far, everything works fine. The Dockerfile and the devcontainer.json files are pretty simple:

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",
}

Outside of my container, my git path is in the C:\Program Files\... directory. Within my container the git path is /usr/bin/git, which is why I set the "git.path" property up, and I verified this by using the which git command inside my container. Of course, none of the git commands work because they always lead to an error.

fatal: Could not chdir to 'C:/Workspace/my-angular-app': No such file or directory

I could always use the Remote-Containers: Reopen Locally command, and once I'm back in Windows (outside the container), my source control lights up with all my diffs and git works just fine. But, if there is a way to get git to work from within the container it would be helpful. I don't want to constantly have to exit the container to identify the diffs as I'm working on changes.

like image 332
michael Avatar asked Mar 02 '20 19:03

michael


People also ask

Can I use Git in a Docker container?

Even if you are running your project on Docker, you can still access your git account inside Docker Containers. All you need to do is just install Git inside your Docker Container.

How does VS Code remote containers work?

The Visual Studio Code Remote - Containers extension lets you use a Docker container as a full-featured development environment. It allows you to open any folder inside (or mounted into) a container and take advantage of Visual Studio Code's full feature set.


1 Answers

This has been resolved, but it was originally a Docker issue: https://github.com/microsoft/vscode-remote-release/issues/2591

like image 103
michael Avatar answered Sep 18 '22 10:09

michael