编程技术网

关注微信公众号,定时推送前沿、专业、深度的编程技术资料。

 找回密码
 立即注册

QQ登录

只需一步,快速开始

极客时间

为什么我无法将.git文件夹复制到我的Docker容器中:Why can't I copy my .git folder into my docker container

Ashwin H 云计算 2022-5-10 14:53 10人围观

腾讯云服务器
为什么我无法将.git文件夹复制到我的Docker容器中的处理方法

我们有一个node.js/typescript项目,现在我应该为声纳分析提供数据.

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

我们使用docker容器在测试完成后运行测试,然后运行声纳分析,因此我们可以使用测试中的代码覆盖率报告.

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.

唯一的问题是,责任信息缺失.这就是为什么我尝试将.git文件夹复制到Docker容器中的原因,但到目前为止我没有成功.这是我的Dockerfile的内容.

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"] 

我已经读到,.dockerignore文件可以用于排除文件或文件夹,但是我们没有使用这种文件,我还尝试创建一个仅包含node_modules的文件,但是该文件也不起作用.

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.

有人知道如何将其包括在内吗?我只找到如何从docker容器中排除.git",但是到目前为止,还原这些提示并没有帮助.

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.

使用 COPY使其变得更加陌生../在图像中包含.git文件夹.

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

问题解答

您将.git文件夹的内容复制到了/dist目录中,而不是.git文件夹本身中.如果要复制文件夹,请将目标指定为要创建的文件夹:

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/ 

这篇关于为什么我无法将.git文件夹复制到我的Docker容器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程技术网(www.editcode.net)!

腾讯云服务器 阿里云服务器
关注微信
^