'enable_ip_masquerade and WSL2 Bridge

I'm using Docker in WSL2 on my Windows machine. I have problems connecting to a docker image (for example if I launch a docker image from a PostGres database, I can't connect to it from a client on my windows), and similarly way, I'm having trouble building a python image that needs to look for dependencies or if I log into a shell of my docker image, an "apt get update" won't work. In short, my docker images don't seem to be able to connect to the network of my windows machine and vice versa. If I look at the list of my networks:

    docker network inspect bridge
[
    {
        "Name": "bridge",
        "Id": "0b6e2f8d7966d6910cd99e8225c673576e8e07d0838e21efe23041b4779c59d6",
        "Created": "2022-04-11T08:49:02.8718184+02:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "7aef4a3f6b81abb00da33e86a3320b5c506f19818fc603913a7b2bed94777ef4": {
                "Name": "portainer",
                "EndpointID": "56f9990dbab6a6b78f4a618c55662f6396504552fe942336413d05d9289ab9f5",
                "MacAddress": "02:42:ac:12:00:02",
                "IPv4Address": "172.18.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "false",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

If I understood the documentation correctly, I thought the problem came from the "enable_ip_masquerade" option which should be "true"... But I couldn't find anywhere how to change this value. Can you confirm/deny that this is the option that needs to be changed? And how to make this change?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source