Context

When running az acr build or az acr run from a local checkout, Azure CLI archives and uploads the build context to ACR managed storage using .dockerignore to exclude local directories such as .azure/ or secrets/. Standard Docker directory rules ending in / work in docker build, so it is easy to assume Azure CLI honors them the same way.

The insight

Unlike Docker’s own build context archiver, Azure CLI’s ACR context archiver (verified in azure-cli 2.88.0, azure/cli/command_modules/acr/_archive_utils.py) only strips trailing slashes on negation rules starting with !.

  • Positive directory exclusion rules such as .azure/ or secrets/ compile to anchored regexes ending in /$ (for example, ^\.azure/$).
  • Python tarfile member names (tarinfo.name) carry no trailing slash, so those regexes never match.
  • Running az acr build or az acr run silently uploads directories that docker build excludes into ACR managed storage and remote build runners with no warning.

Workaround

Omit trailing slashes on positive directory rules, or use a deny-by-default allowlist with explicit nested globs:

.dockerignore
# Avoid (silently ignored by az acr build / run):
# .azure/
# secrets/
# Option 1: omit trailing slashes on positive directory rules
.azure
secrets
**/*.env
# Option 2: deny-by-default allowlist
*
!src
!Dockerfile

Docs checked

Not found on these official pages (no claim is made about other pages):