我已经找了两天了,似乎找不到一个直接的答案。
如何在我的Docker容器中使用SSL在Windows10上运行.NET 5项目?(仅限于地方发展)
VisualStudio2019设置我的项目,以便它使用带有Desktop的Dockerfile在容器中运行我的项目。问题是,我需要它在HTTPS上服务和发送数据,因为我的web客户端(单独的项目)也使用HTTPS。但是在谷歌搜索了几天之后,我似乎找不到一个直接的答案来解决如何使用.NET 5和Docker在Windows上配置它。
我希望这将是一个配置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
}
}
}当我运行我的容器时,它确实会像我期望的那样在address https://localhost:44398/上打开我的浏览器,但是浏览器当然会抱怨没有证书。
我做什么好?
发布于 2022-01-31 23:11:27
如果其他人遇到这种情况,下面就是你要做的事情;
无论是在运行您的应用程序的同一个容器中,还是在一个单独的容器中,然后通过某种Ingress (或类似的设置)相互通信,都可以创建一个nginx或apache服务器。
设置此服务器,使其充当反向代理。所有传入呼叫都会转到nginx/apache服务器,然后由nginx/apache服务器将这些调用委托给服务器应用程序并返回。
https://stackoverflow.com/questions/70438348
复制相似问题