---
title: "az acr build and run silently ignore .dockerignore rules with trailing slashes"
url: "https://www.dariuszparys.com/notes/az-acr-build-ignores-dockerignore-trailing-slashes"
author: "Dariusz Parys"
published: 2026-11-30T00:00:00.000Z
description: "az acr build and az acr run upload directories that .dockerignore excludes with a trailing slash, because the Azure CLI context archiver matches those rules against tar member names that have no trailing slash."
tags:
  - "Azure"
  - "Azure CLI"
  - "Docker"
  - "Security"
---

# az acr build and run silently ignore .dockerignore rules with trailing slashes

## 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:

```text title=".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):

- [az acr - Azure CLI Reference](https://learn.microsoft.com/cli/azure/acr)
- [Automate container builds with Azure Container Registry tasks](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-tasks-overview)
- [Tutorial: Quick Docker image build with Azure ACR Tasks](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-tutorial-quick-task)
- [Frequently asked questions - Azure Container Registry](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-faq)
- [YAML reference for Azure Container Registry Tasks](https://learn.microsoft.com/en-us/azure/container-registry/container-registry-tasks-reference-yaml)
- [Azure CLI release notes](https://learn.microsoft.com/cli/azure/release-notes-azure-cli)
