如何在不提供Git仓库的情况下创建Azure ACR任务?
问题:如何创建无需Git仓库的Azure ACR任务?
我曾使用以下命令成功创建Azure ACR任务:
az acr task create --registry myregistry \ --name demo_task \ --image demo_app:{{.Run.ID}} \ --file demo.Dockerfile \ --context https://github.com/hm-group/repo.git#branch \ --git-access-token your_token --debug
但我不想依赖Git仓库,只想通过--file参数创建任务,于是执行了以下命令:
az acr task create --registry productionai \ --name demo_task \ --image demo_app:{{.Run.ID}} \ --file demo.Dockerfile
执行后出现错误:
If the task is not a System Task, --context-path must be provided.
请问如何正确创建无需Git仓库的Azure ACR任务?
解决方案
ACR任务要求必须指定构建上下文(即使不使用Git仓库),你需要添加--context参数指向本地目录作为构建上下文,通常用当前目录(.)即可。
正确的命令示例:
az acr task create --registry productionai \ --name demo_task \ --image demo_app:{{.Run.ID}} \ --file demo.Dockerfile \ --context .
补充说明:
- 如果你的
demo.Dockerfile不在当前工作目录,需要指定其相对/绝对路径,比如--file ./docker/demo.Dockerfile,同时--context .保持指向当前目录作为构建上下文。 - 若要创建系统任务(不推荐用于常规构建场景),可添加
--system-task参数,但系统任务主要用于ACR的自动化运维场景,比如镜像清理、漏洞扫描等,不适合普通镜像构建任务。
内容的提问来源于stack exchange,提问作者Python coder
相关产品推荐
相关产品推荐

