Harsha Sukeerthi
Harsha Sukeerthi

Reputation: 21

"cannot listen on the TCP port: bind: cannot assign requested address" error from podman when creating new containers

I have Windows 10 host system with WSL2, hosting a Linux VM (Fedora CoreOS instantiated by podman as podman machine), and podman client running on Windows 10 host. When I try to create sample container with below command:

podman run -ip 192.168.1.3:8080:8080/tcp --name webserver_1 registry.fedoraproject.org/f29/httpd:latest

I get, "Error: preparing container 7c0f2a6f2eba7b414542f8e297f1698e1375f38506dfa06adc7ccbdef416d090 for attach: cannot listen on the TCP port: listen tcp4 192.168.1.3:8080: bind: cannot assign requested address"

but same works if I don't specify any host IP (as per podman documentation, "If host IP is set to 0.0.0.0 or not set at all, the port will be bound on all IPs on the host.").

So, I have two problems:

  1. If I don't specify any host IP, then I see port 8080 being open only on local host IP (127.0.0.1), I get this information from netstat command:

TCP 127.0.0.1:8080 0.0.0.0:0 LISTENING 15396 [wslhost.exe]

Not on 0.0.0.0: TCP 0.0.0.0:8000 0.0.0.0:0 LISTENING 4 Can not obtain ownership information TCP 0.0.0.0:8005 0.0.0.0:0 LISTENING 4 Can not obtain ownership information TCP 0.0.0.0:8020 0.0.0.0:0 LISTENING 4 Can not obtain ownership information TCP 0.0.0.0:8050 0.0.0.0:0 LISTENING 6340 Can not obtain ownership information TCP 0.0.0.0:8088 0.0.0.0:0 LISTENING 9560

  1. If I specify any specific IP, then I get above error on "bind: cannot assign requested address" error.

Podman machine (Fedora CoreOS) is running in rootless mode.

I tried creating container using docker client and get the same error (which I expected to happen), as this being very fundamental, I am not sure about the mistake that I am making. I see many posts / questions similar to mine, but I don't see any concrete solution. Port 8080 on host is not the problem, because I get error no matter which host port that I select.

Upvotes: 1

Views: 5158

Answers (1)

Harsha Sukeerthi
Harsha Sukeerthi

Reputation: 21

[[host_ip]:port]:container_port option provided with -p in podman command, here host_ip is not IP of Windows host system, but IP of Linux VM running in WSL, Linux VM did not have this IP, port forwarding failed, so the second problem above is a usage issue.

For the first issue, a port in Windows host is opened on loopback IP for every port that is open on either 0.0.0.0 or WSL_IP on the Linux VM, so port not opening on 0.0.0.0 on Windows host is also expected, either:

  1. IP forwarding using netsh (ex: netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=8080 connectaddress=127.0.0.1), only works for TCP ports, OR
  2. Any generic TCP / UDP reverse proxies have to be used.

Upvotes: 1

Related Questions