Search code examples
dockerwindows-subsystem-for-linux

Losing connectivity in WSL2 after docker start


I lose connectivity in my WSL2 when I start docker

$ curl google.fr                                                                                                    
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">


$ sudo service docker start

$ curl google.fr          
<timeout>

I know all about WSL2 connectivity issues with VPN and cisco anyconnect.
But in this particular case I'm not connected to any VPN.

To restore connectivity to the internet I have to do wsl --shutdown in PowerShell. But then I lose docker...


Solution

  • Found a simple fix.

    The pb commes from docker using the same network than WSL2.
    To fix this issue you should explicitly tell docker to use a different network.

    Add this to your /etc/docker/daemon.json

    {
        "bip" : "10.10.0.1/16"
    }
    

    If the file doesn't already exists, create it.

    Credits : https://github.com/microsoft/WSL/issues/4285#issuecomment-1180567785


    Now that the bip is different you will probably need to update it on other technologies relying on docker. For instance on minikube you must define the new bip as a parameter during launch.
    For ie :

    minikube start --docker-opt bip=10.10.0.1/16 
    

    EDIT

    Some time later all stoped working once again. To fix it I deactivated self generating resolv.conf (sudo nano /etc/wsl.conf) then killed wsl2 using powershell with wsl --shutdown. Opened a new shell, started docker then edited /etc/resolv.conf and replaced the content with nameserver 8.8.8.8. After exiting, internet connectivy was back.

    Don't ask why ! Just have faith...