FaceRecognitionDotNet人脸识别项目发布到linux服务器docker容器详细教程

钱钊
2023-12-01

本人服务器为linux Ubuntu
首先新增Dockerfile,我使用的Dockerfile文件如下:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base

WORKDIR /app
EXPOSE 8000
EXPOSE 9000

WORKDIR /app
COPY .   /app
ENTRYPOINT ["dotnet", "FaceApi.dll"]

项目在docker上可以正常发布,但是FaceRecognition.Create(@“./models”)这句代码一直报错,错误如下

 Unable to load shared library 'DlibDotNetNativeDnn' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libDlibDotNetNativeDnn: cannot open shared object file: No such file or directory

经过百度搜索国内几乎找不到相关文档,果断谷歌,之后经过谷歌搜索发现在docker build的时候需要安装libopenblas-dev,因为FaceRecognitionDotNet依赖于它,而且必须安装在docker容器的环境中,如果只装在本机上那么在docker中还是会报错,然后修改Dockerfile如下

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
RUN apt-get update && apt-get install -y \
    libopenblas-dev \
    liblapack-dev \
    libx11-6 \
    libgdiplus \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app
EXPOSE 8000
EXPOSE 9000

WORKDIR /app
COPY .   /app
ENTRYPOINT ["dotnet", "FaceApi.dll"]

新增如下代码是用于安装相关依赖的

RUN apt-get update && apt-get install -y \
    libopenblas-dev \
    liblapack-dev \
    libx11-6 \
    libgdiplus \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

重新build又报错:

Some index files failed to download. They have been ignored, or old ones use

就是下载东西超时之类的,又一顿谷歌,找到解决办法:
在/etc/docker目录下建立新文件daemon.json,并输入如下内容:

{
   "dns":["8.8.8.8", "114.114.114.114"]
}

然后重启docker sudo systemctl restart docker
重新build发现下载依赖包特别慢,解决办法是更换为华为国内镜像源:

RUN  sed -i s@/deb.debian.org/@/mirrors.huaweicloud.com/@g /etc/apt/sources.list
RUN  apt-get clean
RUN  apt-get update

重新build终于成功!
完整的Dockerfile文件如下:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base

RUN  sed -i s@/deb.debian.org/@/mirrors.huaweicloud.com/@g /etc/apt/sources.list
RUN  apt-get clean
RUN  apt-get update
RUN apt-get update && apt-get install -y \
    libopenblas-dev \
    liblapack-dev \
    libx11-6 \
	libgdiplus \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app
EXPOSE 8000
EXPOSE 9000

WORKDIR /app
COPY .   /app
ENTRYPOINT ["dotnet", "FaceApi.dll"]

另外提一下,如果发布到windows server iis服务器上报错找不到模块,那么需要安装 Microsoft Visual C++
附下载链接:
Microsoft Visual C++ 2005

Microsoft Visual C++ 2005 Redistributable Package (32位)

http://download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x86.exe

Microsoft Visual C++ 2005 Redistributable Package (64位)

http://download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x64.exe

Microsoft Visual C++ 2008

Microsoft Visual C++ 2008 Redistributable Package (32位)

https://download.microsoft.com/download/9/7/7/977B481A-7BA6-4E30-AC40-ED51EB2028F2/vcredist_x86.exe

Microsoft Visual C++ 2008 Redistributable Package (64位)

https://download.microsoft.com/download/9/7/7/977B481A-7BA6-4E30-AC40-ED51EB2028F2/vcredist_x64.exe

Microsoft Visual C++ 2010

Microsoft Visual C++ 2010 SP1 Redistributable Package (32位)

https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x86.exe

Microsoft Visual C++ 2010 SP1 Redistributable Package (64位)

https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x64.exe

Microsoft Visual C++2012

Visual C++ Redistributable for Visual Studio 2012 Update 4 (32位)

https://download.microsoft.com/download/9/C/D/9CD480DC-0301-41B0-AAAB-FE9AC1F60237/VSU4/vcredist_x86.exe

Visual C++ Redistributable for Visual Studio 2012 Update 4 (64位)

https://download.microsoft.com/download/9/C/D/9CD480DC-0301-41B0-AAAB-FE9AC1F60237/VSU4/vcredist_x64.exe

Microsoft Visual C++2013

Visual C++ Redistributable Packages for Visual Studio 2013 (32位)

https://download.microsoft.com/download/F/3/5/F3500770-8A08-488E-94B6-17A1E1DD526F/vcredist_x86.exe

Visual C++ Redistributable Packages for Visual Studio 2013 (64位)

https://download.microsoft.com/download/F/3/5/F3500770-8A08-488E-94B6-17A1E1DD526F/vcredist_x64.exe

Microsoft Visual C++2015-2022

Visual Studio 2015, 2017, 2019, and 2022 (32位)

https://aka.ms/vs/17/release/vc_redist.x86.exe

Visual Studio 2015, 2017, 2019, and 2022 (64位)

https://aka.ms/vs/17/release/vc_redist.x64.exe

下载后运行并按照安装页面提示进行安装。

注意:不同版本间的安装界面会不一样,但操作流程基本相同。

 类似资料: