The reason I want to change it is because at the moment, when I connect via postman to https://localhost:59541, I get Error: Client network socket disconnected before secure TLS connection was established
If you try it and it gives you an error message or does not work, then it is probably not possible I still don’t understand that port configuration but I ignore that for the moment since it may not be relevant. I assume you know what you are doing. I have never tried 0 as a target port. I googled it and if I understand it, this is a special port to tell the system to find a suitable port. I don’t know if it is possible to use it as a target port or just for a listening address (I guess this is the case), but I would not do it anyway. When you run a container, you want to know what service is listening on what port. And since it is inside a container, you don’t even need to worry about that a port is already used by an other service.
So since I can’t do more than check that configuration myself on my machine, which you can do too, I leave it to you. If you get an arror message that you don’t understand, we can try to explain that to you.
update:
If the error message in the title is the result of your test using port 0 as target, than probably this is the answer.
Sorry, I forgot the title when I came back to to topic
Hi! Thanks for taking the time to answer this. I am unfamiliar with Docker as I am new to it.
This port configuration(with other port numbers):
443/tcp 0.0.0.0:59541
59541/tcp 0.0.0.0:0
59542/tcp 0.0.0.0:0
80/tcp 0.0.0.0:59542
was set automatically when I ran my docker compose for my other project. It works properly.
The issue now is that I am unable to use Postman to connect to my api because I get this error:
Error: Client network socket disconnected before secure TLS connection was established
This is the strangest thing. This is my Dockerfile:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
ENV ASPNETCORE_URLS=http://+:80
ENV ASPNETCORE_ENVIRONMENT=Development
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
#Add the nuget line if building locally
COPY ["../NuGet.Config", "."]
COPY ["AppOne.Api/AppOne.Api.csproj", "AppOne.Api/"]
COPY ["AppOne.ClassLibrary/AppOne.ClassLibrary.csproj", "AppOne.ClassLibrary/"]
COPY ["AppOne.Data/AppOne.Data.csproj", "AppOne.Data/"]
COPY ["AppOne_AS.Connect/AppOne_AS.Connect.csproj", "AppOne_AS.Connect/"]
RUN dotnet restore "AppOne.Api/AppOne.Api.csproj"
COPY . .
WORKDIR "/src/AppOne.Api"
RUN dotnet build "AppOne.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "AppOne.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "AppOne.Api.dll"]
It runs perfectly without https. I am unable to run this with Https as for some reason my env variables arent being read and I will get an invalid cert error.
Does that mean that theres something wrong with my docker compose? How am I able to run this just fine?
In the referred tpic that is not port 0, just the IP address to listen on every available IP addresses. I would understand that, but you want to use port 0 as target port.
HTTPS is not just a choice that you make and tell the server to listen on HTTPS protocol. You need to provide TLS certificates. This is true with and without Docker too. I don’t see certificates in your shared codes.
Again. I don’t see any certificate settings in your code.
Since I am not a ASPNET developer, I have no idea how TLS works with ASPNET. If you can make it work without Docker or at least you can enter the container and check the HTTPS acces from inside the container without error, than we can try to figure out what is required to make it work from outside.