【Container App】Container App无法从Container Registries 拉取镜像
问题描述
基于目前对Azure的资源的安全性合规要求,都需要开启防火墙并且关闭公网访问。 当ACR ( Azure Container Registries )启用了防火墙并关闭公网访问后。
引起了一个新的问题:Container App无法拉取ACR中的镜像!
错误信息:
{"TimeStamp":"2025-07-30 12:58:24.9603413 \u002B0000 UTC","Type":"Warning","ContainerAppName":"xxxxx","RevisionName":"xxxxx--0000001","ReplicaName":"xxxxx--0000001-56db958c8b-k97xk","Msg":"Container \u0027xxxxx\u0027 was terminated with exit code \u0027\u0027 and reason \u0027
ImagePullFailure
\u0027. Pull image: xxxxxxx.azurecr.cn/mynodejsalbum:v1 failed with exit code: 1, error: time=\u00222025-07-30T12:58:24Z\u0022 level=info msg=\u0022trying next host\u0022 error=\u0022failed to authorize: failed to fetch anonymous token: unexpected status from GET request to https://xxxxxxx.azurecr.cn/oauth2/token?scope=repository%3Amynodejsalbum%3Apull\u0026service=xxxxxxx.azurecr.cn:403 Forbidden
\u0022 host=xxxxxxx.azurecr.cn\nctr: failed to resolve reference \u0022xxxxxxx.azurecr.cn/mynodejsalbum:v1\u0022: failed to authorize: failed to fetch anonymous token: unexpected status from GET request to https://xxxxxxx.azurecr.cn/oauth2/token?scope=repository%3Amynodejsalbum%3Apull\u0026service=xxxxxxx.azurecr.cn: 403 Forbidden\n.","Reason":"ContainerTerminated","EventSource":"ContainerAppController","Count":1}
问题解答
这个问题的原因有两点:
1) ACR 中没有设置允许ACA访问的白名单
2) ACA的出口IP地址并不固定。它可能会使用所在数据中心的出口IP段中的某一个IP,如果要指定固定的出口IP,需要使用NAT Gateway来实现!
基于以上原因,这里推荐使用ACR的Private Endpint来解决访问403问题 ( https://learn.microsoft.com/en-us/azure/container-registry/container-registry-private-link )
PS: 为何在启用了Azure Trusted Services后,Azure数据中心的服务也无法访问呢? 原因是目前ACR指支持四种服务可以Bypass访问。ACA不在其中!
- Azure Container Instances
- Microsoft Defender for Cloud
- Machine Learning Azure
- Container Registry
配置Private Endpint的步骤简单,但是需要注意:必须选择与ACA所在的VNET相通的网络(同一个VNET或之间有peering) 。
最好 最好 是启用Private Endpint后,在ACA中使用 curl -v https://<yourACRhost> 来验证是否是私网IP地址,是否可以连通!
如下图测试结果:
PS:如果在配置Container App的页面中发现无法列出当前ACR的镜像列表,这是因为当前浏览器所在的环境的IP地址无法访问ACR,在ACR中添加当前IP地址访问后就可以解决此问题!
参考资料
Trusted services :https://learn.microsoft.com/en-us/azure/container-registry/allow-access-trusted-services
Connect privately to an Azure container registry using Azure Private Link : https://learn.microsoft.com/en-us/azure/container-registry/container-registry-private-link
评论