rancher-desktop icon indicating copy to clipboard operation
rancher-desktop copied to clipboard

Port mapping uses same host port for different container ports (one IPv4 and the other v6)

Open douglascamata opened this issue 1 year ago • 1 comments

Actual Behavior

Rancher Desktop is mapping two different container ports to the same host port.

Steps to Reproduce

  1. Start this test container: docker run -it --rm -d -p 80 -p 81 --name web nginx

Result

  1. After the web container started, run docker port web
  2. Output will be like so:
80/tcp -> 0.0.0.0:49376
80/tcp -> :::49375
81/tcp -> 0.0.0.0:49375
81/tcp -> :::49374

As you can see, this is quite a mess and uses 3 ports:

  • Port 80 IPv4 maps to 49376
  • Port 80 IPv6 maps to 49375 (why not 49376?)
  • Port 81 IPv4 maps to 49375 (same as 80 on IPv6!)
  • Port 81 IPv6 maps to 49374

Expected Behavior

Rancher Desktop should map the two listener of each container port to the same host port, just like Docker.

When I run the same steps to reproduce and see the results in a Linux machine I get this:

80/tcp -> 0.0.0.0:49154
80/tcp -> :::49154
81/tcp -> 0.0.0.0:49153
81/tcp -> :::49153

As you can see, it's quite simple: each container port got mapped to a single host port, using the same port across IPv4 and IPv6, and only 2 ports are used.

Additional Information

I suspect there could be some concurrency issue with assigning node ports, not sure.

I run some testing scripts that rely on a considerable amount of concurrent processes creating networks, then scheduling containers, and fetching the host ports to send requests. All this besides the inter-container communications (in the same network). I often see intermittent and weird network errors running these scripts that aren't present on a Linux machine or with Docker Desktop. A few times, some of these errors indicate that a request ends up going to the wrong port of a container.

Rancher Desktop Version

1.5.1

Rancher Desktop K8s Version

Not applicable.

Which container engine are you using?

moby (docker cli)

What operating system are you using?

macOS

Operating System / Build Version

macOS 12.5

What CPU architecture are you using?

arm64 (Apple Silicon)

Linux only: what package format did you use to install Rancher Desktop?

No response

Windows User Only

No response

douglascamata avatar Aug 24 '22 10:08 douglascamata

Thanks for the bug report!

I tried this on PopOS 20.04 and was not able to reproduce it:

/home/adam/dev/suse/rancher-desktop〉docker run -it --rm -d -p 80 -p 81 --name web nginx                                                                                08/24/2022 11:19:00 AM
c74e62a87712fd792251893e9b3d146241626e60a8e032a9bd1df432d220138e
/home/adam/dev/suse/rancher-desktop〉docker port web                                                                                                                    08/24/2022 11:19:04 AM
80/tcp -> 0.0.0.0:49156
80/tcp -> :::49156
81/tcp -> 0.0.0.0:49155
81/tcp -> :::49155

Of course, Linux is a different platform. We should try to repro this on macOS.

adamkpickering avatar Aug 24 '22 17:08 adamkpickering

Makes sense that it works with Rancher on Linux, @adamkpickering, as this scenario isn't much different than just running Docker on Linux (without Docker Desktop).

I don't know a lot about the interactions and configuration of Lima used by Rancher Desktop in macOS, but I wouldn't be surprised if it was somehow related to this problem. 🤔

Let me know if there are tests I could run locally to provide more information. I am happy to help.

douglascamata avatar Aug 25 '22 08:08 douglascamata

Believe it or not, the setup for macOS and Linux is actually pretty similar for RD - both use lima to run docker, k8s etc in a VM. But there are some differences when it comes to networking that I'm not very familiar with.

@dpmerrill is there any chance you could try to repro this on your M1 machine? My hands are kind of tied without a mac.

adamkpickering avatar Aug 26 '22 16:08 adamkpickering

I'm also not able to reproduce this issue on my M1 running 12.5.1:

~: docker port web
80/tcp -> 0.0.0.0:49154
80/tcp -> :::49154
81/tcp -> 0.0.0.0:49153
81/tcp -> :::49153

But this does appear to be a known moby issue: https://github.com/moby/moby/issues/42442 We're probably not seeing this on our systems because it can take a while to show up.

dpmerrill avatar Aug 27 '22 17:08 dpmerrill