How should I configure my Dockerfile so that the ports map as desired? My current Dockerfile looks like this:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1903 AS base
WORKDIR /app
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build
WORKDIR /src
COPY [My.API/My.API.csproj", "My.API/"]
RUN dotnet restore "My.API/My.API.csproj"
COPY . .
WORKDIR "/src/My.API"
RUN dotnet build "My.API.csproj" -p 51005:443 -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "My.API.csproj" -p 51005:443 -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "My.API.dll"]
I would like to map port 51005 to port 443 in my Docker container so that when I call it through Postman using a command like this https://localhost:51005/api/my things should work.
However, when I run docker ps the port assigned is never the specified port. I get 0.0.0.0:5182->443/tcp. What should I change? Do I need to specify the port mapping in both the build and the publish lines? Thanks.