skip to Main Content

I am using remote container extension in VSCode to work with my docker containers. While I am able to make a remote connection to my client container for example, the git history is showing most of the files as modified or deleted. How do I go about keeping git in-sync with my local project structure?

My local setup looks as the following,

- app
   - client
      - .devcontainer
      - Dockerfile
   - server
      - .devcontainer
      - Dockerfile
   - docker-compose.yml

My docker-compose.yml

version: '3'
services:
  server:
    build: ./server
    volumes:
      - ~/.ssh:/root/.ssh
      - ./server/src:/app/src
      - api-modules:/app/node_modules
  client:
    build: ./client
    depends_on:
      - server
    volumes:
      - ~/.ssh:/root/.ssh
      - ./.git:/app/.git
      - web-modules:/app/node_modules
      - ./client/src:/app/src
      - ./client/public:/app/public
volumes:
  api-modules:
  web-modules:

Client Dockerfile

FROM node:10

COPY . /app/

WORKDIR /app

ENTRYPOINT yarn start;

2

Answers


  1. Let’s see, currently…

    • … you copy /app into the container (with same path) during container creation.
    • … You mount ./.git as volume into /app/.git

    That means /app is at the state your local directory was in when the container was created the last time.
    While /app/.git is reflecting your current local state (because it’s a mounted volume reading from your local ./.git).
    That’s why git in the container will see working directory differences as its contents are not in the state git expects them to be (based on git’s history/state stored in .git).

    Solutions:

    Either remove the /app/.git-volume from docker-compose.yml and re-create the container whenever you changed the code (to update /app/).

    Or mount ./ as volume to /app/ in the container (not just the subdir .git), instead of copying /app in the Dockerfile.

    Login or Signup to reply.
  2. In you docker-compose file you can create and mount the volume client_path to /app

    example:

      client:
        volumes:
        - <client_path>:/app
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search