【问题标题】:Need help enabling SSL for Docker project with SignalR and .NET 5需要帮助使用 SignalR 和 .NET 5 为 Docker 项目启用 SSL
【发布时间】:2022-01-23 01:06:23
【问题描述】:

我已经搜索了两天了,我似乎无法找到一个直接的答案;

如何在 Windows 10 上运行 .NET 5 项目的 Docker 容器中使用 SSL? (仅用于本地开发)

Visual Studio 2019 设置我的项目,以便它使用 Dockerfile 和 Docker Desktop 在容器中运行我的项目。问题是,我需要它通过 HTTPS 服务和发送数据,因为我的 Web 客户端(单独的项目)也使用 HTTPS。但是在谷歌上搜索了几天之后,我似乎无法找到如何在 Windows 上使用 .NET 5 和 Docker 进行配置的直接答案。

我希望这是一个配置 Dockerfile 的问题,以便在构建过程中启用它,但似乎这不是它的工作方式。

我的 Dockerfile 如下所示:

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["infuse-signalr-server/infuse-signalr-server.csproj", "infuse-signalr-server/"]
RUN dotnet restore "infuse-signalr-server/infuse-signalr-server.csproj"
COPY . .
WORKDIR "/src/infuse-signalr-server"
RUN dotnet build "infuse-signalr-server.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "infuse-signalr-server.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "infuse-signalr-server.dll"]

在我的launchSettings.json 文件中,我有以下内容:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "https://localhost:44398",
      "sslPort": 44398
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "infuse_signalr_server": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "dotnetRunMessages": "true",
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    },
    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
      "publishAllPorts": false,
      "useSSL": true
    }
  }
}

当我运行我的容器时,它确实在地址 https://localhost:44398/ 上打开了我的浏览器,正如我所期望的那样,但是浏览器当然会抱怨没有证书。

我该怎么办?

【问题讨论】:

    标签: docker https .net-5 docker-desktop


    【解决方案1】:

    如果其他人遇到这种情况,这就是你要做的;

    在您运行应用程序的同一个容器中,或者在一个单独的容器中,然后通过某种 Ingress(或类似设置)相互通信,创建一个 nginx 或 apache 服务器。

    设置此服务器,使其充当反向代理。所有传入调用都转到 nginx/apache 服务器,然后将这些调用委托给服务器应用程序并返回。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-04
      • 2014-02-01
      • 1970-01-01
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多