Podman: Networking in WSL

Check if you have any Podman machine available:

podman machine list
# OR
podman machine ls

If you do not have any Podman machine, create it with:

# This will default to podman-machine-default
podman machine init

# If you have a name in mind then you can pass it
podman machine init my-podman-machine

Deploy something…

podman run -d --name web-server -p 8000:80 nginx

Normally on Docker you can access this port 8000 from outside your machine. But for Podman in WSL you will need to add extra command.

Open Windows Terminal or Cmd or PowerShell with Administrator privilege.

netsh interface portproxy add v4tov4 [listenport] [connectaddress] [connectport] [listenaddress]
netsh interface portproxy add v4tov4 8000 172.19.92.131 8000 *
# OR
netsh interface portproxy add v4tov4 listenport=8000 listenaddress=* connectport=8000 connectaddress=172.19.92.131

The listenaddress=* parameter will listen from 0.0.0.0 and from your ip address e.g. 192.168.1.100. If you want more control over this you can make two separate rules.

# This command will allow only request from 192.168.1.100 (HOST)
netsh interface portproxy add v4tov4 listenport=8000 listenaddress=192.168.1.100 connectport=8000 connectaddress=172.19.92.131

# This command will allow only request from 0.0.0.0 (OUTSIDE)
netsh interface portproxy add v4tov4 listenport=8000 listenaddress=0.0.0.0 connectport=8000 connectaddress=172.19.92.131

Now you should be able to access 192.168.1.100:8000 from the host and from neighbouring machines.

If you still cannot access it from outside (neighbouring machines) then make sure you turn off windows firewall (or add port 8000) to the allow list.

References:


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *