使用Docker将AspNetCore应用打包

install-website.ps1的内容可以参考使用PowerShell部署AspNetCore应用到IIS

Dockerfile (使用Muti-stage build的方式)

# 下面的 escape在window系统非常有用,它用以定义在Dockerfile中使用转义字符,Dockerfile中,escape默认为\,这里转义为`,而且必须放在第一行,参考https://blog.csdn.net/chengqiuming/article/details/79007598

# escape=`
# 这里本可以使用如下镜像,用Kerstrel作为WEB服务器,但本文不这样做
#FROM microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016 AS base

# 这里使用官方的Windows Server Core作为基础镜像
FROM microsoft/windowsservercore:latest AS base

# 这里是这个build镜像,专用于build我们的源代码
#FROM microsoft/dotnet:2.1-sdk-nanoserver-1803 AS build
FROM microsoft/dotnet:2.1-sdk-nanoserver-sac2016 AS build
WORKDIR /src

COPY ["./webapi.csproj", "."]

RUN dotnet restore "webapi.csproj"

COPY . .

RUN dotnet build "webapi.csproj" -c Release -o /app

# 这里发部程序
FROM build AS publish
RUN dotnet publish "webapi.csproj" -c Release -o /app

FROM base AS final
# 这里在镜像中启用powershell脚本环境
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

LABEL name="WSR" `
      release-date="2019-1-4"

# Disable DNS cache so container addresses always fetched from Docker
#RUN Set-ItemProperty -path 'HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters' -Name ServerPriorityTimeLimit -Value 0 -Type DWord

# Activate Windows features based on the app's requirements.
#RUN Add-WindowsFeature Web-App-Dev, Web-Net-Ext45, Web-Asp-Net45, Web-ISAPI-Ext, Web-ISAPI-Filter, NET-Framework-45-ASPNET

# 将上面使用powershell脚本Copy到镜像中
RUN New-Item -ItemType Directory C:\install;
COPY .\install-website.ps1    C:\install

# DONT TOUCH - Paths used during CI build after solution MSBUILD.exe
# COPY .\bin\Release\PublishOutput  C:\inetpub\wwwroot\
COPY --from=publish /app C:\inetpub\wwwroot\

RUN 'Log written in docker build' >> 'C:\Logs\docker-build.log';

#这里就是我们上面使用powershell命令安装dotnetcore程序到IIS的脚本
ENTRYPOINT  ["powershell.exe", "C:\\install\\install-website.ps1"]

# 这里可以对你的程序作一些健康检查
# HEALTHCHECK --interval=60s --timeout=60s --start-period=100s --retries=3 CMD C:\install\healthcheck.bat
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值