asp.net 核心的 Service Fabric docker 中的 HTTPS 无法正常工作

HTTPS in docker in Service Fabric for asp.net core not working

我有一个 asp.net 核心应用程序托管在 docker 中。 docker 文件看起来像这样

FROM  mcr.microsoft.com/dotnet/core/aspnet:3.1
LABEL cmbappname="autocomplete"
ARG source
WORKDIR /cmbapp
ADD ${source} . 
ENV APP_UTILS=C:\app 
VOLUME ${APP_UTILS}
HEALTHCHECK --retries=5  --interval=100s --start-period=10s   CMD curl --fail http://localhost || exit 1 
ENTRYPOINT ["dotnet", "MyBus.AutoApi.dll"]
EXPOSE 80
EXPOSE 443

托管在服务结构中的 docker 图像具有这样的服务清单

<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="AutoApiPkg"
                 Version="1.0.0"
                 xmlns="http://schemas.microsoft.com/2011/01/fabric"
                 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <ServiceTypes>
    <!-- This is the name of your ServiceType.
         The UseImplicitHost attribute indicates this is a guest service. -->
    <StatelessServiceType ServiceTypeName="AutoApiType" UseImplicitHost="true" />
  </ServiceTypes>

  <!-- Code package is your service executable. -->
  <CodePackage Name="Code" Version="1.0.0">
    <EntryPoint>
      <!-- Follow this link for more information about deploying Windows containers to Service Fabric: https://aka.ms/sfguestcontainers -->
      <ContainerHost>
        <ImageName>autoApi</ImageName>
      </ContainerHost>
    </EntryPoint>
    <!-- Pass environment variables to your container: -->

    <EnvironmentVariables>
      <EnvironmentVariable Name="ASPNETCORE_ENVIRONMENT" Value="Debug" />

      <EnvironmentVariable Name="ASPNETCORE_URLS" Value="https://*:443/;http://*:80/;https://*:54100/;http://*:54200/"/>
    </EnvironmentVariables>


  </CodePackage>

应用程序清单中的容器策略

 <Policies>
      <ContainerHostPolicies CodePackageRef="Code"  AutoRemove="false"  UseDefaultRepositoryCredentials="false"   ContainersRetentionCount="2"  RunInteractive="true">
        <!-- See https://aka.ms/I7z0p9 for how to encrypt your repository password -->
        <PortBinding ContainerPort="443" EndpointRef="AutApiTypeEndpoint" />
        <PortBinding ContainerPort="80" EndpointRef="LocalAutApiTypeEndpoint" />
        <RepositoryCredentials  AccountName="[AzureContainerUserName]" Password="[AzureContainerPassword]" PasswordEncrypted="false"/>
        <HealthConfig   IncludeDockerHealthStatusInSystemHealthReport="true" RestartContainerOnUnhealthyDockerHealthStatus="false" />            
      </ContainerHostPolicies>
      
    </Policies>

应用程序在没有环境变量“ASPNETCORE_URLS”的情况下运行并正常运行

但是在添加 env 变量时它不起作用,也无法访问。

调试容器给出以下错误日志

Unable to start Kestrel. System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be fo und or is out of date.

  1. 获取证书,例如使用 Letsencrypt [example],或使用 self-signed 证书(用于测试)。
  2. 使用 volume 将证书文件附加到您的容器。
  3. 使用环境变量指示证书的存储位置:
ASPNETCORE_Kestrel__Certificates__Default__Path=certificate.pfx
  1. 使用另一个环境变量提供密码以允许访问私钥:
ASPNETCORE_Kestrel__Certificates__Default__Password="****"

更多信息here