如何防止Dockerfile缓存git克隆 [英] How to prevent Dockerfile caching git clone
问题描述
这是Dockerfile快照:
........
RUN git clone - depth = 1 git-repository-url $ GIT_HOME /
运行mvn包-Dmaven.test.skip
........
我希望docker不缓存的步骤运行git clone --depth = 1 git-repository-url $ GIT_HOME /
,以便存储库上正在进行的更新可以反映在Docker映像构建中。
另一个解决方法:
如果您使用github(或gitlab或bitbucket太可能),您可以将github API的代理代码添加到虚拟位置。
添加https://api.github.com/repos/$USER/$REPO/git/refs/heads/$BRANCH version.json
运行git clone -b $ BRANCH https:// github。 com / $ USER / $ REPO.git $ GIT_HOME /
api调用将返回不同的结果,当如果您正在处理私人回扣,您可以使用 auth /#basic-authenticationrel =nofollow noreferrer> github的
x-oauth-basic
认证方案
ADD https:// $ ACCESS_TOKEN:x-oaut h-basic@api.github.com/repos/$USER/$REPO/git/refs/heads/$BRANCH version.json
(thx @captnolimar为建议编辑以澄清身份验证)
I have a Dockerfile trying to package and deploy a web app to a container. The code of app fetches from git repository during Docker image building. Here's the Dockerfile snapshot:
........
RUN git clone --depth=1 git-repository-url $GIT_HOME/
RUN mvn package -Dmaven.test.skip
........
I want the docker do not cache the step of RUN git clone --depth=1 git-repository-url $GIT_HOME/
so that the on-going updated on the the repository can be reflected on the Docker image building. Is it possible to a achieve that?
Another workaround:
If you use github (or gitlab or bitbucket too most likely) you can ADD the github API's representation of your repo to a dummy location.
ADD https://api.github.com/repos/$USER/$REPO/git/refs/heads/$BRANCH version.json
RUN git clone -b$BRANCH https://github.com/$USER/$REPO.git $GIT_HOME/
The api call will return different results when the head changes, invalidating docker's cache.
If you're dealing with private repos you can use github's x-oauth-basic
authentication scheme with a personal access token like so:
ADD https://$ACCESS_TOKEN:x-oauth-basic@api.github.com/repos/$USER/$REPO/git/refs/heads/$BRANCH version.json
(thx @captnolimar for a suggested edit to clarify authentication)
这篇关于如何防止Dockerfile缓存git克隆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!