rancher-sandbox / rancher-desktop

Container Management and Kubernetes on the Desktop
https://rancherdesktop.io
Apache License 2.0
6.04k stars 285 forks source link

"Connection reset by peer" when docker container has explicit port forwarding to 127.0.0.1 #7720

Open jhollmannk opened 3 weeks ago

jhollmannk commented 3 weeks ago

Actual Behavior

When you define port forwarding for a docker container in a docker-compose to be restricted to 127.0.0.1 via

ports:
  - 127.0.0.1:80:80

you cannot access this container and get an error message like "Connection reset by peer".

Steps to Reproduce

Use moby as the docker runtime. Disable traefik (or the whole kubernetes) so that you can use port 80.

Start a simple nginx container with the following docker-compose.yml:

services:
  nginx:
    container_name: nginx
    image: nginx
    ports:
      - 127.0.0.1:80:80

with docker compose up -d. Then try curl http://localhost in a DOS-box or another WSL terminal.

Result

curl fails with the error message "curl: (56) Recv failure: Connection reset by peer".

Expected Behavior

The welcome page of the nginx container should be downloaded.

Additional Information

The download works if you omit the 127.0.0.1 restriction of the port in the docker-compose.yml.

In both cases (with or without the 127.0.0.1 restriction) the host-switch.exe process has the listening port open on 127.0.0.1:80 on my PC. I have RancherDesktop installed only for me (not all users) so that is the expected behaviour.

But I think with the restriction the connection inside the rancher-desktop WSL fails. This was not the case some time ago before the network stack on windows was changed.

I think this should work, right? I mean, with Rancher-Desktop installed only for me, all connections to forwarded ports only work on my machine (localhost/127.0.0.1). So the restriction in the docker-compose.yml should not hinder that in any way.

Rancher Desktop Version

1.16.0

Rancher Desktop K8s Version

1.30.4

Which container engine are you using?

moby (docker cli)

What operating system are you using?

Windows

Operating System / Build Version

Windows 10 Enterprise 22H2

What CPU architecture are you using?

x64

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

None

Windows User Only

No response