I have let Visual Studio 2019 create the standard GRPC .Net Core template program as a starting point. I have also ticked the option to let the GRPC service run inside a Docker (Linux/WSL2) container.
My problem is, that the port under which I can reach the docker image, is constantly changing and I cannot find a way to assign a static one.
If I use https://localhost:32776, I can reach the service insider the Docker container. However, the port portion is changing with each restart of the container. Is there a way to always use the same port, e.g. 5001?
That's my Dockerfile as automatically created by Visual Studio: #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/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["GrpcService/GrpcService.csproj", "GrpcService/"]
RUN dotnet restore "GrpcService/GrpcService.csproj"
COPY . .
WORKDIR "/src/GrpcService"
RUN dotnet build "GrpcService.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "GrpcService.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "GrpcService.dll"]
And this is launchSettings.json:
{
"profiles": {
"GrpcService": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001"
},
"Docker": {
"commandName": "Docker",
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"publishAllPorts": true,
"useSSL": true
}
}
}