Mapped PublicPort in ContainerListResponse is wrong
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.
- Start a container with a mapped port. In this case kafka with port mapping 0.0.0.0:51147->9092
- Get a ContainerListResponse by calling ListContainersAsync see here
- 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:
I just found out that the response from the docker daemon is wrong. This has nothing to do with this library
@eifinger Can you elaborate a bit more of what was wrong and how to fix it?
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.
@AndersRasmussen seems like this has to do something with wsl2: https://github.com/HofmeisterAn/dotnet-testcontainers/issues/386#issuecomment-858382857
@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.
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.