Search code examples
dockerasp.net-core

What is default https port for asp.net core docker image


# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0.0-windowsservercore-ltsc2022
WORKDIR /App
#mount a volume to folder App
ENTRYPOINT ["dotnet", "AspNetCoreSample.dll"]
EXPOSE ???

The docker container defines environment variable for default HTTP port to be 8080, but what about https?

which port should I expose for https?


Solution

  • The default is to listen for HTTP traffic on port 8080 and not listen for HTTPS traffic.

    For ASP.NET images prior to version 8, the default was to listen for HTTP traffic on port 80.

    More info here: https://learn.microsoft.com/en-us/dotnet/core/compatibility/containers/8.0/aspnet-port

    As for EXPOSE, that doesn't actually do anything. It mainly acts as documentation as to what ports the image uses. And like other documentation, it can be wrong. From the docs

    The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published.

    If you want your app to listen for HTTPS traffic, you should configure it by setting the environment variable ASPNETCORE_HTTPS_PORTS to the port(s) you want. And then you can EXPOSE that port so whoever runs the image can easily find the information.