dockervisual-studioidentityserver4duende-identity-server

Duende IdentityServer will not listen on port 443 while running as a docker container


Running the application from Visual Studio (debugging as Docker), it reports that it's listening on both port 80 and 443 as expected.

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

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

However, while running with "docker run" command, it only listens on port 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

The dockerfile is mostly generated from VS and looks like this

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"]

The launchSettings.json settings for Docker is set up like this

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

Not quite sure what to look for in order to resolve this.


Solution

  • You need to set the environment variable ASPNETCORE_URLS to "https://+:443;http://+:80"

    Easiest way is to update your Dockerfile to include

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