【Azure App Service for Container】记一次拉取镜像失败的特殊情况
问题描述
使用Azure App Service For Container 拉取 应用镜像,发现拉取失败。
错误消息:
“Image pull failed since Inspect image returned null: xxxxxxx.azurecr.cn/dataapi:20230830V2.0”
CreateImageAsync() for xxxxxxx.azurecr.cn/dataapi:20230830V2.0 failed with Ex : DockerApiException: Docker API responded with status code=InternalServerError, response={"message":"Get \"https://xxxxxxx.azurecr.cn/v2/dataapi/manifests/20230830V2.0 \": unauthorized: authentication required, visit https://aka.ms/acr/authorization for more information."}
问题解答
在App Service 的Kudu站点中检查docker日志,发现拉取镜像遇见错误
ERROR - failed to register layer: Error processing tar file(exit status 1): Container ID 1389985163 cannot be mapped to a host ID
这说明容器镜像中使用的UID ‘1389985163’ 超出了App Service 所在虚机允许的 UID范围。因在构建镜像时,使用 docker build --squash 命令构建的 Image 中仍然包含多层 fs layer。该方法无法解决特殊owner uid的问题。
解决方法有
方式一: 更改base image避免了引入包含特殊owner uid的文件目录
方式二:通过 docker export / docker import 的方法生成只有一层fs layer的镜像。
docker export container-id -o tarfile
docker import tarfile newimage:version
方式三:使用以下命令更改owner,并使用docker export/docker import 生成新的镜像
RUN find /usr/local/lib/node_modules/ ! -user root | xargs chown root:root
参考资料
Docker User Namespace remapping issues : https://azureossd.github.io/2022/06/30/Docker-User-Namespace-remapping-issues/index.html#npm-based-projects-causing-userns-remap-exceptions
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2022-08-30 【Azure API 管理】如何修改Azure APIM的管理员邮箱和组织名称
2021-08-30 【Azure 媒体服务】Azure Media Service Explorer 5.4.3.0 不能连接Media Service, 错误消息提示 BadRequest 和 Forbidden
2021-08-30 【Azure 应用服务】VS2019发布应用到正在运行的App Service时失败问题的解决