Docker.DotNet icon indicating copy to clipboard operation
Docker.DotNet copied to clipboard

Mapped PublicPort in ContainerListResponse is wrong

Open eifinger opened this issue 4 years ago • 6 comments

Output of dotnet --info:

.NET SDK (gemäß "global.json"):
 Version:   5.0.201
 Commit:    a09bd5c86c

Laufzeitumgebung:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.201\

Host (useful for support):
  Version: 5.0.4
  Commit:  f27d337295

.NET SDKs installed:
  3.1.407 [C:\Program Files\dotnet\sdk]
  5.0.100 [C:\Program Files\dotnet\sdk]
  5.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

What version of Docker.DotNet?:

3.125.4

Steps to reproduce the issue:

I am using https://github.com/HofmeisterAn/dotnet-testcontainers which uses this library for example here which leads to the describedbehavior.

  1. Start a container with a mapped port. In this case kafka with port mapping 0.0.0.0:51147->9092
  2. Get a ContainerListResponse by calling ListContainersAsync see here
  3. The returned ContainerListResponse object lists the wrong public port. In this case 49160

What actually happened?:

The returned ContainerListResponse object lists the wrong public port. In this case 49160

What did you expect to happen?:

The returned ContainerListResponse object lists the public port 51147

Additional information:

eifinger avatar Apr 08 '21 12:04 eifinger

I just found out that the response from the docker daemon is wrong. This has nothing to do with this library

eifinger avatar Apr 08 '21 13:04 eifinger

@eifinger Can you elaborate a bit more of what was wrong and how to fix it?

AndersRasmussen avatar Jun 01 '21 16:06 AndersRasmussen

Unfortunately I was unable to fix it. I debugged down to the raw json response from the docker daemon and found out it gave false information.

eifinger avatar Jun 01 '21 17:06 eifinger

@AndersRasmussen seems like this has to do something with wsl2: https://github.com/HofmeisterAn/dotnet-testcontainers/issues/386#issuecomment-858382857

eifinger avatar Jun 21 '21 20:06 eifinger

@AndersRasmussen @eifinger I did some further investigation. It seems that WSL2/Minikube+Nginx does remapping of ingress ports AFTER the container was started, and this might take a while.

I've ran docker container ls in a loop on windows and inside WSL2 for a container which exposes port 50787.

Output on linux:

"goofy_wiles" -> "0.0.0.0:50787->5432/tcp"

While the output on windows initially has the same port, after some delay it has another port (and IP):

"goofy_wiles" -> "0.0.0.0:50787->5432/tcp"
"goofy_wiles" -> "127.0.0.1:49156->5432/tcp"

The strange thing is, the Docker.DotNet client returns the following ports (reverse order):

immediatly after start: 49156 after some delay: 50787

Just to note: If I disable minikube, WSL2 and Windows output the same port all the time.

Dont know which component is doing something wrong here, but I guess it's not something which can be fixed in Docker.DotNet - it's probably because of the nginx ingress running insinde my minikube.

prochnowc avatar Jul 06 '21 06:07 prochnowc

BTW, this only seems to happen when docker selects a random host port. If I manually specify the port the "port remapping" does not happen.

prochnowc avatar Jul 06 '21 06:07 prochnowc