【发布时间】:2020-11-04 17:03:43
【问题描述】:
我有一个 .net core 3 应用程序在 本地/开发 运行良好,无论是单独运行还是在 linux 容器中运行。 然后,我使用该应用程序并将其内置到 azure 管道内的 docker 映像中。映像已加载到 Azure 容器注册表。
最后,我有一个Azure Web APP for Containers (Linux),它使用映像来运行。
我在本地设置了 docker-compose 文件,如下所示:
environment:
- "ASPNETCORE_ENVIRONMENT=Development"
...
- "ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx"
- "ASPNETCORE_Kestrel__Certificates__Default__Password=Your_password123"
volumes:
- ~/.aspnet/https:/https:ro
对于生产,我有以下内容:
environment:
- UseInMemoryDatabase=false
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_Kestrel__Certificates__Default__Path=/security/mycert.pfx
- "ASPNETCORE_Kestrel__Certificates__Default__Password=Your_password123"
ports:
- "5000:5000"
- "5001:5001"
volumes:
- fsmount001: /security:/security
- /var/ssl/private:/https
我将“mycert”加载到 azure 门户中,并将其指纹添加到应用程序的配置设置中的 WEBSITE_LOAD_CERTIFICATES
我使用 Open SSL 创建了 mycert 文件,我可以在本地使用它,而 kestral 会使用它,但会出现警告。
问题
当我使用此图像运行应用程序时,我在 docker 日志中收到以下错误:
System.InvalidOperationException:无法配置 HTTPS 端点。 未指定服务器证书,默认开发者 证书找不到或已过期...在 Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
我已经尝试了很多加载证书的变体,但无法让它们中的任何一个工作。 这是一个仅在生产中发生的问题。
我也试过了:
- 购买了 Azure 应用证书并使用了 thumbprint.p12 文件,例如:
- ASPNETCORE_Kestrel__Certificates__Default__Path=/var/ssl/private/<thumbprint>.p12
- ASPNETCORE_Kestrel__Certificates__Default__Password=""
我没有使用密码,因为当您购买证书时没有设置密码
-
下载购买的 App Cert 并使用 open ssl 创建密码链接的 .pfk 文件并将其作为另一个私钥上传
-
使用 azure 文件挂载并上传我的开发证书文件并从文件挂载中引用它们,例如:
- ASPNETCORE_Kestrel__Certificates__Default__Path=/security/mycert.com.pfx
- ASPNETCORE_Kestrel__Certificates__Default__Password="Your_password123"
volumes:
- fsmount001: /security:/security
编辑 1:完整的 docker-compose 和 azure 文件设置
有一个安全文件夹,里面有 mycert.pfx 文件
- 这是我在 azure 应用服务配置中设置文件挂载的方法:
我将挂载路径设置为我的文件共享中的安全文件夹
- 这是完整的 docker compose 文件:
services:
webui:
image: ${DOCKER_REGISTRY-}webui
build:
context: .
dockerfile: src/WebUI/Dockerfile
environment:
- UseInMemoryDatabase=false
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=https://+:443;http://+:80
- "ConnectionStrings__DefaultConnection=****"
- ASPNETCORE_Kestrel__Certificates__Default__Path=/secure/mycert.pfx
- ASPNETCORE_Kestrel__Certificates__Default__Password="Your_password123"
ports:
- "5000:5000"
- "5001:5001"
volumes:
- fsmount001: /secure
- ~/var/ssl/private:/https
restart: always
volumes:
fsmount001:
driver: azure_file
driver_opts:
share_name: st-*****tus
storage_account_name: st********001
编辑 2:码头文件
有关更多上下文,您可以在下面找到我的 dockerfile
请注意,我使用的是开源应用程序模板/框架 cleanarchiecture。您可以看到我正在尝试将 docker pull request 用于 repo 作为基本代码。我的目标是在 azure ci/cd 管道中“dockerize”这个基础框架,并将其部署到 azure web app for containers (linux)
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
ENV ASPNETCORE_URLS=https://+:5001;http://+:5000
WORKDIR /app
EXPOSE 5000 5001 2222
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt install -y nodejs
WORKDIR /src
COPY ["src/WebUI/WebUI.csproj", "src/WebUI/"]
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"]
RUN dotnet restore "src/WebUI/WebUI.csproj"
COPY . .
WORKDIR "/src/src/WebUI"
RUN dotnet build "WebUI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebUI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CleanArchitecture.WebUI.dll"]
谁能帮我弄清楚如何在 Linux 容器中为 kestral 设置证书?
提前致谢
【问题讨论】:
标签: azure docker .net-core docker-compose azure-web-app-service