Visual Studio Duodecad IT IdentityServer在作为Docker容器运行时不会侦听端口443

uz75evzq  于 2023-10-23  发布在  Docker
关注(0)|答案(1)|浏览(155)

从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
}

我不知道该怎么解决这个问题。

eh57zj3b

eh57zj3b1#

您需要将环境变量ASPNETCORE_URLS设置为“https://+:443;联系我们
最简单的方法是更新你的Dockerfile,

ENV ASPNETCORE_URLS="https://+:443;http://+:80"

相关问题