Why can't I copy my .git folder into my docker container
Asked Answered
G

3

12

We have got a node.js/typescript project and now I am supposed to provide data to our sonarqube analysis.

We are using a docker container to run our tests in and after the tests are finished, we are running the sonarqube analysis so we can use the code coverage report from the tests for it.

The only problem is, that the blame information is missing. This is why i tried to copy the .git folder into the docker container, but so far I did not succeed. This is the content of my Dockerfile.

FROM node:11.6-alpine
RUN apk --update add openjdk8-jre

WORKDIR /dist

COPY package*.json ./

RUN npm install

COPY src/ ./src/
COPY test/ ./test/
COPY ts*.json ./
COPY sonar-project.properties ./
COPY test.sh /
COPY .git/ ./

RUN chmod +x /test.sh

CMD ["sh", "/test.sh"]

I have read, that the .dockerignore file can be used to exclude files or folder but we are not using such a file and I also tried creating one that only contains node_modules, but that also did not work.

Has anybody got any idea how to include it or any tipp what to google? I only find "how to exclude .git from the docker container" but reverting those tipps did not help so far.

Edit: To make it even stranger using COPY . ./ includes the .git folder into the image.

Gailgaile answered 11/1, 2019 at 15:42 Comment(0)
V
20

You copied the contents of the .git folder into the /dist directory, not the .git folder itself. If you want to copy the folder, specify the target as the folder you want to create:

COPY .git/ ./.git/
Viccora answered 11/1, 2019 at 16:40 Comment(0)
J
1

Ensure that the .git folder is not contained within a .dockerignore file within your project. This was the cause of the problem in this related question.

Judi answered 11/8 at 20:22 Comment(0)
C
0

I also tried below instruction instead of COPY .git/ ./.git/ and it was successfully copied .git directory to the docker container:

ADD . .
Countryfied answered 28/8, 2022 at 7:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.