使用自签名证书在Docker中部署Asp.Net Core(Abp)项目
一 编写Dockerfile文件
FROM mcr.microsoft.com/dotnet/aspnet:6.0 COPY / /app WORKDIR /app EXPOSE 80 ENTRYPOINT ["dotnet", "Acme.BookStore.Web.dll"] # 设置时区 RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime RUN echo 'Asia/Shanghai' >/etc/timezone
二 生成镜像
docker build -t acme.bookstore .
三 生成证书(macOs及Windows)
dotnet dev-certs https -ep ${HOME}/.aspnet/https/aspnetapp.pfx -p <CREDENTIAL_PLACEHOLDER>
dotnet dev-certs https --trustf
四 运行容器映像
docker pull mcr.microsoft.com/dotnet/samples:aspnetapp
docker run --rm -it -p 8000:80 -p 8001:443 -e ASPNETCORE_URLS="https://+;http://+" -e ASPNETCORE_HTTPS_PORT=8001 -e ASPNETCORE_Kestrel__Certificates__Default__Password="<CREDENTIAL_PLACEHOLDER>" -e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx -v ${HOME}/.aspnet/https:/https/ mcr.microsoft.com/dotnet/samples:aspnetapp
引用:使用 Docker over HTTPS 托管 ASP.NET Core 映像 | Microsoft Learn