netcore 3.1 webapi部署到docker的坑

原文 https://blog.csdn.net/puzi0315/article/details/104417514/
参考另一资料 https://www.cnblogs.com/shapman/p/13545457.html
坑1:默认镜像的系统:

.netcore 3.1 默认镜像Debian系统的。若系统不对,则会出现异常。我们的系统是Ubuntu,则用 3.1-bionic

坑2:一直报没有安装SDK:

报错信息如下:

/bin/bash:warning:setlocale:LC_ALL:cannot change locale (zh_CN.UTF-8)
It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from :
https://aka.ms/dotnet-download

根据调试,我们的最终的dockerfile文件内容如下:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic
WORKDIR /app
EXPOSE 80
EXPOSE 443
 
#ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=SkyAPM.Agent.AspNetCore
#ENV SKYWALKING__SERVICENAME=MuXue.Zyiz.Template.WebApi
ENV LANG zh_CN.UTF-8
ENV LANGUAGE $LANG
ENV LC_ALL $LANG
ENV TZ=Asia/Shanghai
RUN echo $TZ > /etc/timezone && \
    apt-get update && apt-get install -y tzdata && \
    rm /etc/localtime && \
    ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
    dpkg-reconfigure -f noninteractive tzdata && \
    apt-get clean
RUN mkdir -p /usr/local/tomcat/webapps
 
COPY publish ./
 
# install tingyun agent
#RUN chmod +x ./tingyun-agent-netcore-1.5.2.bin
#RUN ./tingyun-agent-netcore-1.5.2.bin --license=xxxxxxxxx
#RUN rm -f ./tingyun-agent-netcore-1.5.2.bin
 
# setup env for tingyun agent
#ENV CORECLR_ENABLE_PROFILING 1		
#ENV CORECLR_PROFILER {8BEB2128-D285-4E1D-91B6-11ACD43EC0EE}		
#ENV CORECLR_PROFILER_PATH /usr/lib/tingyun-dotnet/x64/tingyun_profiler.so
#ENV LD_LIBRARY_PATH /usr/lib/tingyun-dotnet/x64:$LD_LIBRARY_PATH
#ENV TINGYUN_NETCORE_HOME /usr/lib/tingyun-dotnet
#ENV TINGYUN_APP_NAME muxue-zyiz-net-api
 
RUN chmod +x ./entrypoint.sh
ENTRYPOINT ["/bin/bash", "./entrypoint.sh"]
CMD ["dotnet", "MuXue.Zyiz.Template.WebApi.dll"]
在webapi的web项目根目录再创建entrypoint.sh,内容如下:

#!/bin/bash
 
cp -rf /usr/local/tomcat/webapps/..data/* ./
 
exec "$@"

将Dockerfile和entrypoint.sh 分别设置:

属性-复制到输出目录:始终复制

posted @ 2021-01-11 10:45  过错  阅读(697)  评论(0编辑  收藏  举报