azure-cli: --build-arg causes failed builds in Azure Container Registry

I have been trying to use --build-arg to inject Git hashes and build dates like I do in local builds, but whenever I try to use it it inevitably gives me an error in the build agent:

An image does not exist locally with the tag: acmedockerimages.azurecr.io/youtube-dl
"docker build" requires exactly 1 argument.
See 'docker build --help'.

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

Since the option is documented, I assume it works. So far I have tried:

local-build:
	docker build \
		--build-arg BUILD_DATE=$(BUILD_DATE) \
		--build-arg VCS_REF=$(VCS_REF) \
		-t $(LOCAL_IMAGE_NAME) .

cloud-build:
	az acr build \
		--registry $(REGISTRY_NAME) \
		--build-arg BUILD_DATE=$(BUILD_DATE) \
		--build-arg VCS_REF=$(VCS_REF) \
		--image $(CONTAINER_NAME) .

…and…

local-build:
	docker build \
		--build-arg BUILD_DATE=$(BUILD_DATE) \
		--build-arg VCS_REF=$(VCS_REF) \
		-t $(LOCAL_IMAGE_NAME) .

cloud-build:
	az acr build \
		--registry $(REGISTRY_NAME) \
		--build-arg "BUILD_DATE=$(BUILD_DATE)" \
		--build-arg "VCS_REF=$(VCS_REF)" \
		--image $(CONTAINER_NAME) .

but only this works:

cloud-build:
	az acr build \
		--registry $(REGISTRY_NAME) \
		--image $(CONTAINER_NAME) .

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 2
  • Comments: 19 (6 by maintainers)

Most upvoted comments

I’m also hitting this and I think the only real solution is for you to fix your az acr build implementation so it packages up the arguments into a file that is then shipped to the server for execution so that any double quoting issues can be handled correctly on your side rather than allowing it to turn into an impossible to debug shell issue on the server side. For example I have this powershell code:

$rc = az acr build --image snpe/quantizer:v1 --registry $registry_name --resource-group $resource_group `
  --secret-build-arg MODEL_STORAGE_CONNECTION_STRING=$Env:MODEL_STORAGE_CONNECTION_STRING `
  --build-arg SNPE_SDK=$snpe_sdk_url --build-arg SNPE_SDK_FILENAME=$snpe_sdk_filename --build-arg SNPE_ROOT=/home/chris/$snpe_root `
  --build-arg ANDROID_NDK=$android_ndk_url --build-arg ANDROID_NDK_FILENAME=$android_ndk_filename --build-arg ANDROID_NDK_ROOT=/home/chris/$android_ndk_root `
  --secret-build-arg GITHUB_PAT=$Env:GITHUB_PAT .

And I get this completely useless and totally bogus error message:

"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage:  docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
/bin/sh: 1: --build-arg: not found]