title: Docker+WSL2+.Net Core Assign constant port that works with localhost
body: <p>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.</p>
  <p>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.</p>
  <p><a href="https://i.stack.imgur.com/9ripF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9ripF.png" alt="enter image description here" /></a></p>
  <p>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?</p>
  <p>That's my Dockerfile as automatically created by Visual Studio:
  #See <a href="https://aka.ms/containerfastmode" rel="nofollow noreferrer">https://aka.ms/containerfastmode</a> to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.</p>
  <pre><code>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 [&quot;GrpcService/GrpcService.csproj&quot;, &quot;GrpcService/&quot;]
  RUN dotnet restore &quot;GrpcService/GrpcService.csproj&quot;
  COPY . .
  WORKDIR &quot;/src/GrpcService&quot;
  RUN dotnet build &quot;GrpcService.csproj&quot; -c Release -o /app/build
  
  FROM build AS publish
  RUN dotnet publish &quot;GrpcService.csproj&quot; -c Release -o /app/publish
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app/publish .
  ENTRYPOINT [&quot;dotnet&quot;, &quot;GrpcService.dll&quot;]
  </code></pre>
  <p>And this is launchSettings.json:</p>
  <pre><code>{
    &quot;profiles&quot;: {
      &quot;GrpcService&quot;: {
        &quot;commandName&quot;: &quot;Project&quot;,
        &quot;environmentVariables&quot;: {
          &quot;ASPNETCORE_ENVIRONMENT&quot;: &quot;Development&quot;
        },
        &quot;applicationUrl&quot;: &quot;https://localhost:5001&quot;
      },
      &quot;Docker&quot;: {
        &quot;commandName&quot;: &quot;Docker&quot;,
        &quot;launchUrl&quot;: &quot;{Scheme}://{ServiceHost}:{ServicePort}&quot;,
        &quot;publishAllPorts&quot;: true,
        &quot;useSSL&quot;: true
      }
    }
  }
  </code></pre>