Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

copy

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.

like image 206
Woozar Avatar asked Jan 11 '19 15:01

Woozar


1 Answers

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/
like image 106
BMitch Avatar answered Nov 15 '22 10:11

BMitch