执行az acr build时提示“not a git repository”的问题求助
解决Azure Container Registry构建时Git仓库检测错误
问题原因
Azure Container Registry(ACR)的构建任务在执行依赖扫描时,会尝试在构建上下文中查找Git仓库信息。当你使用本地目录(.)作为构建上下文时,上传到ACR的上下文通常不包含.git文件夹(可能被本地.gitignore排除,或ACR默认忽略该目录),导致ACR的构建环境无法识别Git仓库,从而抛出fatal: not a git repository错误。
解决方案
方案1:跳过依赖扫描
如果你的构建不需要依赖扫描功能,直接添加--skip-dependency-scanning参数禁用该功能即可解决问题:
az acr build --image sample/hello-world:v1 --registry az204acrcarol --resource-group az204-acr-rg --skip-dependency-scanning .
方案2:使用Git仓库URL作为构建上下文
如果需要保留依赖扫描,直接将Git仓库URL作为构建上下文传入,ACR会自动克隆完整的仓库(包含.git文件夹),确保依赖扫描能正常执行:
az acr build --image sample/hello-world:v1 --registry az204acrcarol --resource-group az204-acr-rg https://github.com/aclimarin/az204.git
若Dockerfile不在仓库根目录,添加--file参数指定路径,例如:
az acr build --image sample/hello-world:v1 --registry az204acrcarol --resource-group az204-acr-rg --file ./path/to/Dockerfile https://github.com/aclimarin/az204.git
内容的提问来源于stack exchange,提问作者Ana Carol
相关产品推荐
相关产品推荐

