2

I am new to Docker and buidling a docker-compose file to setup my nodejs dev environment from a single file. Idea is to give a docker-compose file to a developer from where they can simply spin up the containers and start development.

When I docker-compose up, the application is built and runs with success. But my problem is when I open it in dev containers in Vscode, it fails to recognize as a git repo.

.dockerignore

node_modules
npm-debug.log

Dockerfile

FROM node:16.15.0 as develop-stage
WORKDIR /code
COPY package.json .
# Using package-lock file to fix the version of installed modules.
COPY package-lock.json .
RUN npm install
COPY . .
EXPOSE 9608
CMD ['nodemon' 'index.js']

Docker-compose

version: '3.8'
services:
  my-service:
    container_name: my-service
    build: 
      context: 'https://username:[email protected]/abc/test-repo'
      dockerfile: Dockerfile
    volumes:
      - my-data:/code
    command: nodemon index.js
    networks:
      - my-network
    expose:
      - 9608
    ports:
      - 9608:9608
    restart: on-failure
volumes:
  my-data:
    external: false
networks:
  my-network:
    external: false
7
  • When running ls -a inside the container on the root folder do you see a .git folder? Commented Mar 9, 2023 at 5:46
  • @brianangulo No Commented Mar 9, 2023 at 5:51
  • Do you have a .dockerignore file, and if so what does it contain? Commented Mar 9, 2023 at 5:57
  • 1
    @1615903 I have udpated my question with a dockerignore file. Commented Mar 9, 2023 at 6:00
  • What if you try to explicitly copy it: COPY .git/ ./.git/? Commented Mar 9, 2023 at 6:05

1 Answer 1

0

Your .git folder is not within the root directory that's being copied over to the docker image. Depending on how your folder structure is set up it may be a folder or 2 above. You can find it by cd .. && ls -a until found. Then use an explicit COPY ../.git . to add it into the Docker image.

Sign up to request clarification or add additional context in comments.

2 Comments

Couldnt find the git folder in the image. or maybe dockerfile copies "visible" folder ?
Updated my answer. I meant within your root directory before it gets copied over to the docker image. Your .git folder holds all of the git metadata so the goal is to find out where it is and COPY it into the image. Sometimes if you set up your folder as below so where is it? ` app/ .git/ <--- your git folder code/ <--- your app here package.json index.js `

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.