Duende IdentityServer 在作为 docker 容器运行时不会监听端口 443

问题描述 投票:0回答:1

从 Visual Studio 运行应用程序(作为 Docker 进行调试),它报告它正在按预期侦听端口 80 和 443。

[05:08:57 Information] Microsoft.Hosting.Lifetime
Now listening on: https://[::]:443

[05:08:57 Information] Microsoft.Hosting.Lifetime
Now listening on: http://[::]:80

但是,当使用“docker run”命令运行时,它仅侦听端口 80。

docker run -d -p 9441:443 -p 9442:80 --name duendetest test/duendeserver:1.0

[05:16:48 Information] Microsoft.Hosting.Lifetime

    Now listening on: http://[::]:80

dockerfile 大部分是从 VS 生成的,看起来像这样

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

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["Test.DuendeServer/Test.DuendeServer.csproj", "Test.DuendeServer/"]
RUN dotnet restore "Test.DuendeServer/Test.DuendeServer.csproj"
COPY . .
WORKDIR "/src/Test.DuendeServer"
RUN dotnet build "Test.DuendeServer.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Test.DuendeServer.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

# Install ca-certificates for certificate management
RUN apt-get update && apt-get install -y ca-certificates

# Create a directory for custom certificates
RUN mkdir /usr/local/share/ca-certificates/my_custom_certs

# Copy certificate to the container
COPY Test.DuendeServer/certificates/ /usr/local/share/ca-certificates/my_custom_certs/

# Update the trusted certificates store
RUN update-ca-certificates

ENTRYPOINT ["dotnet", "Test.DuendeServer.dll"]

Docker 的 launchSettings.json 设置是这样设置的

"Docker": {
  "commandName": "Docker",
  "launchBrowser": true,
  "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
  "publishAllPorts": true,
  "useSSL": true
}

不太确定要寻找什么来解决这个问题。

docker visual-studio identityserver4 duende-identity-server
1个回答
0
投票

您需要将环境变量 ASPNETCORE_URLS 设置为“https://+:443;http://+:80”

最简单的方法是更新 Dockerfile 以包含

ENV ASPNETCORE_URLS="https://+:443;http://+:80"
© www.soinside.com 2019 - 2024. All rights reserved.