【Azure App Service for Container】记一次拉取镜像失败的特殊情况

发布时间 2023-08-30 20:24:14作者: 路边两盏灯

问题描述

使用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