Az acr build parses all files in repo even if excluded in .dockerignore
Describe the bug
I am trying to build a docker image with az acr build -t <repo/name:tag> -f Dockerfile -r <registry> . and I have a .dockerignore file with .venv in it. However az acr build parses all files within the dockerignore file, and it is very slow. It just does not ignore the folder, but parses every file within ignored folders. I don't think this should happen
Related command
az acr build -t <repo/name:tag> -f Dockerfile -r <registry> .
Errors
After more than 30min, I get an error:
Packing source code into tar to upload...
[Errno 2] No such file or directory: '.\\.venv\\bin\\python3.12'
Issue script & Debug output
Long logs of the form cli.azure.cli.command_modules.acr._archive_utils: .dockerignore: no rule for '.venv/lib/python3.12/site-packages/pyright/dist/dist/typeshed-fallback/stubs/TgCrypto'. parent ignore 'True'
Expected behavior
Running az acr build should be fast even if I am using a virtual environment
Environment Summary
azure-cli 2.71.0 core 2.71.0 telemetry 1.1.0 Extensions: bastion 1.4.0 ssh 2.0.6 Dependencies: msal 1.31.2b1 azure-mgmt-resource 23.1.1 Python location 'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe' Config directory 'C:\Users\javierzazo.azure' Extensions directory 'C:\Users\javierzazo.azure\cliextensions' Python (Windows) 3.12.8 (tags/v3.12.8:2dc476b, Dec 3 2024, 19:30:04) [MSC v.1942 64 bit (AMD64)]
Legal docs and information: aka.ms/AzureCliLegal
Your CLI is up-to-date.
Additional context
No response
Thank you for opening this issue, we will look into it.
Here are some similar issues that might help you. Please check if they can solve your problem.
- #17493
Possible solution (Extracted from existing issue, might be incorrect; please verify carefully)
Try removing the trailing '/'s in your .dockerignore file and let me know if that works. This will hopefully be working by the next CLI release, but I don't want you to have to wait until then.
Reference:
- https://github.com/azure/azure-cli/issues/17493#issuecomment-1253026203
- https://github.com/azure/azure-cli/issues/17493#issuecomment-1253276839
Powered by issue-sentinel
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @toddysm, @luisdlp, @northtyphoon, @terencet-dev.
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @toddysm, @luisdlp, @northtyphoon, @terencet-dev.
May I also add, that parsing .dockerignore does not follow same rules as .gitignore? For example **/.venv does not capture .venv at the root, as it should. Can this be fixed and support exactly .gitignore rules?
And the fact that this tools parses .venv even if excluded, makes the tool unusable because of its slowness. Have you verified this is the case? Can you reproduce my issue? Thanks.
I'm having a similar issue where the .dockerignore file is completely ignored in the following directory structure:
docker/
dashboard.Dockerfile
dashboard.Dockerfile.dockerignore
dashboard/
...
common/
...
Docker automatically picks up the dashboard.Dockerfile.dockerignore file but az acr build does not.
I'm also seeing this in AZ CLI v2.75.0.
Running az acr build takes an extremely long time because it's trying to package up the node_modules folder which is clearly excluded in the .dockerignore file.
In my case the node_modules folder lives inside a subfolder ui which has it's own .dockerignore relevant to the UI components and the az acr build is being called from the root directory since the Dockerfile includes components from sever different subfolders.
If I add **/node_modules to the .dockerignore file in the root of my project, then the folder is properly excluded and the upload process of the build goes much faster though the .dockerignore files in child folder should indeed be honored.
I created this issue on 11 April. Still no updates, no fixes.
same issue here
@leodewang is the PM for ACR Tasks. Would you mind following up on this issue? Thanks
Hi @jzazo , @julesbertrand , @DCMattyG ,
We are fixing the issue in az acr build ACR task to shortcut the check and exclude the special folder directly in CLI https://github.com/Azure/azure-cli/pull/32241. This feature is under maintenance so we priotized bug fix over new features.
Will let you know if there is a new release available in Azure CLI which includes the fix.
Hey @FeynmanZhou thank you. It's not only about excluding .venv, which is a nice short term solution, but excluding all files and folders based on .dockerignore would be nice. Do you think this feature could be done too ?
I'm seeing this issue when trying to actually include a folder (.git in my case) into the build context.
As it currently defaults to ignore it, I'm following the solution presented here: https://learn.microsoft.com/en-us/azure/container-registry/container-registry-faq#how-do-i-include-the--git-folder-in-az-acr-build-command-
However, even with the .dockerignore containing !.git/** line (tested with all sort of variations as well), az acr build still ignores it no matter what.
Logs I'm seeing:
WARNING: cli.azure.cli.command_modules.acr._archive_utils: Excluding '.git' based on default ignore rules
DEBUG: cli.azure.cli.command_modules.acr._archive_utils: .dockerignore: rule '!.git/**' matches '.git/ORIG_HEAD'.
DEBUG: cli.azure.cli.command_modules.acr._archive_utils: .dockerignore: rule '!.git/**' matches '.git/config'.
DEBUG: cli.azure.cli.command_modules.acr._archive_utils: .dockerignore: rule '!.git/**' matches '.git/objects'.
DEBUG: cli.azure.cli.command_modules.acr._archive_utils: .dockerignore: no rule for '.git/objects/61'. parent ignore 'False'
DEBUG: cli.azure.cli.command_modules.acr._archive_utils: .dockerignore: no rule for '.git/objects/61/5fa15e7ff2a5eafc94d4cdb7f087f7ba7c0941'. parent ignore 'False'
DEBUG: cli.azure.cli.command_modules.acr._archive_utils: .dockerignore: no rule for '.git/objects/95'. parent ignore 'False'
DEBUG: cli.azure.cli.command_modules.acr._archive_utils: .dockerignore: no rule for '.git/objects/95/cc1af6ab6433f9513f2f4b547eabc62152ce3b'. parent ignore 'False'
DEBUG: cli.azure.cli.command_modules.acr._archive_utils: .dockerignore: no rule for '.git/objects/59'. parent ignore 'False'
The log clearly shows that the .dockerignore negation rule is matched, but the .git folder is still excluded
My .dockerignore:
!.git/**
node_modules
private
.vscode
.angular
**/.terragrunt-cache
**/secrets/*
## For unknown reasons, NX cannot find the build target in the lib inside a container. Issue and solution documented here: https://github.com/nrwl/nx/issues/23420
.nx
dist/**
Command I'm running:
az acr build \
--registry <my-registry> \
--image <my-image> \
--debug \
--file <my-file> \
.
Az CLI version: 2.78.0
Not sure if my issue is related or even if it's a bug, but that's the only issue I found similar to what I'm currently facing aside from https://github.com/Azure/azure-cli/issues/21114
@leodewang can you take a look?