【问题标题】:ASP.NET Unable to configure HTTPS endpoint - Docker & LinuxASP.NET 无法配置 HTTPS 端点 - Docker 和 Linux
【发布时间】:2021-09-25 10:37:42
【问题描述】:

我的 docker 映像有问题,一个月前它们运行良好,但我做了一个小改动(HTML 更改,在一个小页面中)并尝试重建一个新的 docker 映像。

但是当我部署 docker 镜像时,我收到以下错误消息:

System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-certs https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions, Action`1 configureOptions)
   at Microsoft.AspNetCore.Hosting.ListenOptionsHttpsExtensions.UseHttps(ListenOptions listenOptions)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.AddressesStrategy.BindAsync(AddressBindContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.AddressBinder.BindAsync(IEnumerable`1 listenOptions, AddressBindContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)

这里是设置摘要

我尝试手动构建 docker 映像,也尝试使用我的 CI/CD (AzureDevOps) 自动构建。但两者都产生相同的错误。 我检查了 GIT 历史的任何变化......什么都没有。

这是我使用的 DockerFile

### >>> GLOBALS
ARG ENVIRONMENT="Production"
ARG PROJECT="SmartPixel.SoCloze.Web"

# debian buster - AMD64
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build

### >>> IMPORTS
ARG ENVIRONMENT
ARG PROJECT

ARG NUGET_CACHE=https://api.nuget.org/v3/index.json
ARG NUGET_FEED=https://api.nuget.org/v3/index.json

# Copy sources
COPY src/ /app/src
ADD common.props /app

WORKDIR /app

RUN apt-get update
RUN apt-get install curl
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -
RUN apt-get install -y nodejs
RUN npm install /app/src/SmartPixel.Core.Blazor/

# Installs the required dependencies on top of the base image
# Publish a self-contained image
RUN apt-get update && apt-get install -y libgdiplus libc6-dev && dotnet dev-certs https --clean;\
    dotnet dev-certs https && dotnet dev-certs https --trust;\
    dotnet publish --self-contained --runtime linux-x64 -c Debug -o out src/${PROJECT};

# Execute

# Start a new image from aspnet runtime image
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS runtime

### >>> IMPORTS
ARG ENVIRONMENT
ARG PROJECT

ENV ASPNETCORE_ENVIRONMENT=${ENVIRONMENT}
ENV ASPNETCORE_URLS="http://+:80;https://+:443;https://+:44390" 
ENV PROJECT="${PROJECT}.dll"

# Make logs a volume for persistence
VOLUME /app/Logs

# App directory
WORKDIR /app

# Copy our build from the previous stage in /app
COPY --from=build /app/out ./

RUN apt-get update && apt-get install -y ffmpeg libgdiplus libc6-dev

# Ports
EXPOSE 80
EXPOSE 443
EXPOSE 44390

# Execute
ENTRYPOINT dotnet ${PROJECT}

奇怪的是旧图像(> 1 个月大)都可以正常工作,但在我重建它们时却不行。

这里也是 docker compose 文件:

version: '3.3'
services:
  web:
    image: registry.gitlab.com/mycorp/socloze.web:1.1.1040
    volumes:
     - keys-vol:/root/.aspnet
     - logs-vol:/app/Logs
     - sitemap-vol:/data/sitemap/
    networks:
     - haproxy-net
     - socloze-net
    configs:
     -
      source: socloze-web-conf
      target: /app/appsettings.json
    logging:
      driver: json-file
    deploy:
      placement:
        constraints:
         - node.role == manager
networks:
  haproxy-net:
    external: true
  socloze-net:
    external: true
volumes:
  keys-vol:
    driver: local
    driver_opts:
      device: /data/socloze/web/keys
      o: bind
      type: none
  logs-vol:
    driver: local
    driver_opts:
      device: /data/socloze/web/logs
      o: bind
      type: none
  sitemap-vol:
    driver: local
    driver_opts:
      device: /data/sitemap
      o: bind
      type: none
configs:
  socloze-web-conf:
    external: true

如果出现以下情况,可能是什么原因:

  • 旧图像运行良好
  • 新图像产生此错误
  • 代码没有变化,“DockerFile”没有变化
  • 操作系统是 Debian,Docker 镜像系统是 Ubuntu

你有什么想法吗?我正在寻找几周的解决方案!

【问题讨论】:

  • 您的一个基本图像是否在这段时间内更改\更新?另外,我相信你真的很努力,但如果你包含每个 nessaccery 代码片段,如站点代码、配置、dockerfile 等,它会帮助我们帮助你......
  • 随着证书过期...可能需要或已创建新证书并需要信任 - 正如错误消息所述
  • 导致问题的证书,似乎是由docker文件中的命令“dotnet dev-certs https”生成的证书(这是我的理解)。另一个,似乎工作因为它适用于较旧的图像。(顺便说一句,我尝试删除“... --clean”命令,但它是相同的。

标签: linux docker .net-core certificate haproxy


【解决方案1】:

您需要添加更多环境变量,并且可能还需要安装证书卷:

环境变量及其值:

      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_URLS=https://+:443;http://+:80
      - ASPNETCORE_Kestrel__Certificates__Default__Password=password
      - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/aspnetapp.pfx

和卷:

- ~/.aspnet/https:/https:ro

取决于您计划如何添加这些环境变量和安装卷,例如 dokcer run 或通过 docker-compose,您将不得不在参数列表和正确位置添加双引号。

【讨论】:

  • 谢谢,但是有 haproxy 和浏览器处理的证书。这里的问题是在 docker 镜像和 haproxy 之间。在 DockerFile 中,我们使用“dotnet dev-certs https”为此生成开发证书,它应该足够并且应该可以工作。对吗?(或不是)
猜你喜欢
  • 2020-07-26
  • 2019-02-26
  • 2022-01-01
  • 2014-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-19
  • 1970-01-01
相关资源
最近更新 更多