Search code examples
dockerwindows-subsystem-for-linux

Building a docker image on wsl


I got a new machine and am now using wsl for the first time instead of just ubuntu. I am trying to rebuild one of my projects, but I am unable to build the docker image.

When running docker-compose build I get the error:

ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?                                                                                                                
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

I have tried running:

systemctl start docker

But then I get the error:

System has not been booted with systemd as init system (PID 1). Can't operate.                    
Failed to connect to bus: Host is down 

Can anyone tell me what im doing wrong , please and thank you.


Solution

  • From WSL you actually want to use Docker from the Windows host:

    1. Install Docker Desktop for Windows
    2. Go to the settings > Resources > WSL Integration and flip the switch for the Distros where you want Docker enabled. Screenshot
    3. You should now be able to run docker -v in your WSL commandline and get an output of the Docker version