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 分別設置:

屬性-復制到輸出目錄:始終復制


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM