asquare
asquare

Reputation: 269

How do I use the local git in VS Code, when it is attached to a Docker container?

I am new to VS Code. I have "attached" VS Code to an already running Docker container. My source code resides in the local host machine. The source code folder is mapped to a folder inside the container using "VOLUME /project-home". In VS Code, I am able to open the files within the container and edit/save them.

Now, I am trying to use git which is installed on my local machine within VS Code. But when I click on the "Source Control" icon it says "A valid git installation was not detected" and "Install it or configure it using the 'git.path' setting."

There is some documentation here which I was not able to understand :( https://code.visualstudio.com/docs/remote/containers#_attaching-to-running-containers

I could possibly install git in the container and VS code should be able to recognise it but I want to use the local git. Any idea how to do it ?

Upvotes: 6

Views: 3143

Answers (3)

Benny Chan
Benny Chan

Reputation: 928

If you're using docker compose, run

docker-compose exec [CONTAINER-NAME] apt-get update
docker-compose exec [CONTAINER-NAME] apt-get install git

After install, check the git version with

docker-compose exec [CONTAINER-NAME] which git

Reload Vs code and you're good to go

Upvotes: 1

asquare
asquare

Reputation: 269

After trying different things, ultimately I installed git inside the docker container. VS Code is now able to recognise it and also the changes made to the code. I did not think of it earlier, but the local git is {obviously} able to see the commits made inside the container. This is because the local folder is mounted as a volume inside the container.

Upvotes: 1

szymon
szymon

Reputation: 1030

You don't need git in your Docker container. Make sure your git installed on MacOS is correctly added to PATH.

Here is instruction how to do it: https://stackoverflow.com/a/1835854/6940684.

Replace /usr/local/git/bin with your git installation path if it's different.

Upvotes: 0

Related Questions