- 通过自签发证书方式生成证书
dotnet dev-certs https -ep path.pfx -p 123456 //生成证书
dotnet dev-certs https --trust //信任证书
- 证书包含至项目中失踪复制
- Dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
ENV ASPNETCORE_URLS https://*:443;http://*:80
ENV ASPNETCORE_Kestrel__Certificates__Default__Path /app/testssl.pfx
ENV ASPNETCORE_Kestrel__Certificates__Default__Password 123456
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["Website/Website.csproj", "Website/"]
RUN dotnet restore "Website/Website.csproj"
#COPY . . 这会将本地机器的当前工作目录复制到容器的当前工作目录中。
COPY . .
WORKDIR "/src/Website"
RUN dotnet build "Website.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Website.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Website.dll"]
- 打包运行
docker build --rm -t web .
docker run -d -p 8080:80 -p 8081:443 web
NetCore通过环境变量配置HTTPS发布到Docker