-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Podman container on Windows cannot access host by ip or dns. Linux and Mac OS do not have this issue. #13966
Comments
@n1hility PTAL |
Hey @AddictArts , I have some suggestions that might work for you. The way that WSL does networking is a little different than a classic nested NAT. It's effectively two parallel side-by-side networks with a relay from windows -> linux between them. So in a nutshell, it's easier for windows apps to talk to linux apps than the other way around. The way it works you can't route to 127.0.0.1 on the windows system, but you can route to the internal vlan virtual adapter (called "vEthernet (WSL) " as if it was external. So the solution is to use the vEthernet WSL ip address of your host as the bind address. This should be something like " 172.26.128.1" but IIRC there is some randomization on setup. You can get this address by doing running ipconfig. For example on my host I have:
So you could configure postgres to listen on whatever your 172 address is, and then this address should route from your containers. Alternatively, you could bind to 0.0.0.0 and rely on Windows firewall policy (e.g. restrict the remote side to something like 172.26.0.0/16). In either case though the traffic will be tagged as coming from public, so if you get a Windows Defender prompt for the first postgres run and you do not check the public network, all packets will be dropped. If thats the case you can jump into the Windows Defender Firewall Security settings and delete the block rules for the postgres process and restart (windows defender will reprompt in that case). If you did bind to 0.0.0.0 you would be able to also connect to your 10.x adapter address as you mentioned but only if your firewall policy allows inbound connections that are routable from 172. |
Thank you @n1hility Binding the Windows service postgres to the 172.x.x.x vEthernet address did the trick. However, the Windows firewall was blocking it and not listed in the apps. So adding the postgres.exe in the bin/ dir in Program Files did the trick for the public network. Now the only issue I have is that the container does not run as a daemon. I have to use |
@AddictArts Glad that’s working for you! Could you share more about the daemon problem. Are you saying that if you start a container with -d that it stops running immediately? Thanks! |
@n1hility yes that is exactly right. -d or -dt do not prevent the process from exiting. Using —attach above keeps a stdout etc and the process keeps on executing. I had this exact same issue with running Postgres in a container from podman windows. |
Thanks for the info @AddictArts. Could you give me a set of instructions to reproduce? Does it happen as well on the wsl prompt? (For example, if you do wsl -d podman-machine-default, and then from that prompt run podman commands does that work?) |
Sure can @n1hility From a Windows C:\ prompt using CMD.exe run Postgres will not stay running. This is easier than using the one in this issue since it requires a running postgres Also note you cannot have any others running. If another is running, example without Note: After the above run and it terminating shortly after, if I run As to |
Regarding @n1hility's reply #13966 (comment) on the changing WSL2 IP address: To avoid manually looking up IP's after each WSL2 startup, I make use the fact that this address also shows up as the first address output by
you can use the "host.wsl.internal" name to connect to ports on Windows side, or ports exposed by other containers even. Of course you can choose whatever name you like. This assumes executing the |
BTW you can do something similar in powershell with |
/kind bug
Description
On Windows the container cannot access the host network, localhost, 127.0.0.1, ::1, or by ip assigned with DHCP. An example is
podman run -d --name hasura -p 8080:8080 -e HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:[email protected]:5432/postgres -e HASURA_GRAPHQL_ENABLE_CONSOLE=true -e HASURA_GRAPHQL_DEV_MODE=true -e HASURA_GRAPHQL_ENABLE_TELEMETRY=false docker.io/hasura/graphql-engine:v2.5.0
The hasura container will not see the postgres instance on 192.168.1.5 at port 5432. The exact same on Mac OS does not have this issue. It can see the host services without any special config.
Steps to reproduce the issue:
Describe the results you received:
Error the container tries to connect and fails.
Describe the results you expected:
I expect it to connect and finish running.
Output of
podman version
:Output of
podman info --debug
:Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide? (https://github.com/containers/podman/blob/main/troubleshooting.md)
Yes
The text was updated successfully, but these errors were encountered: