23

I am getting this error while running

>service docker start                                                       
docker: unrecognized service
>service docker.io start                                                    
docker.io: unrecognized service

I am struggling with docker in order to run it. I got Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? error. thereafter I tried several things but it did not work.

>docker pull pstothard/cgview                                               
Using default tag: latest                                                                                      
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

 >sudo docker run hello-world                                                
 docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

>systemctl start docker.service                                             
System has not been booted with systemd as init system (PID 1). Can't operate.

>docker images                                                             
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: 
Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/images/json: dial unix /var/run/docker.sock: connect: permission denied 

>snap stop docker                                                           
Interacting with snapd is not yet supported on Windows Subsystem for Linux.                                      
This command has been left available for documentation purposes only.

I'm using ubuntu 18.04 app in windows system. what should I do?

vibhu sharma
  • 475
  • 1
  • 3
  • 10
  • Is this WSL2 and have you followed [the docs for setting it up with docker](https://docs.docker.com/docker-for-windows/wsl/)? – octagon_octopus Jul 21 '20 at 10:59
  • I don't have WSL2. i have installed docker using sudo apt-get install docker – vibhu sharma Jul 21 '20 at 11:07
  • Well is it WSL 1 then? The output `Interacting with snapd is not yet supported on Windows Subsystem for Linux.` in your screenshot seems to say you are making use of WSL. – octagon_octopus Jul 21 '20 at 11:13
  • @octagon_octopus so what should I do? – vibhu sharma Jul 21 '20 at 11:20
  • I need you to answer my question in my previous comment. I can't help you if I don't know what you are using. If it's WSL 1 then there are plenty of guides on the internet to help you set it up too in case you haven't tried that yet. – octagon_octopus Jul 21 '20 at 11:25
  • @octagon_octopus but how to know what is at the backend WSL1 or something else? – vibhu sharma Jul 21 '20 at 11:31
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/218278/discussion-between-octagon-octopus-and-vibhu-sharma). – octagon_octopus Jul 21 '20 at 11:32

2 Answers2

9

Seems like WSL cannot connect to the docker daemon running through Docker for Windows, probably because it is not exposed or is not running.

WSL1

In case you are using WSL 1, you can expose the docker daemon through this option in Docker for Windows: enter image description here I recommend this article for a detailed guide.

I would highly recommend running docker within WSL 2 instead, since it provides faster boot times and allows docker to use CPU/RAM dynamically instead of you having to preallocate it.

WSL2

In case you are using WSL 2, you will have to enable the WSL 2 back-end for docker through Docker for Windows. The docker team has an extensive guide on this here.

octagon_octopus
  • 1,194
  • 7
  • 10
  • For example in my case I tried to set up docker in wsl2 ubuntu because I didn't want to install Docker for Windows. Isn't there any other way? – Geff Mar 30 '22 at 07:54
  • 1
    @Geff I've got docker working on WSL2 without Docker for Windows before. Unfortunately it's a little too vague to remember the gotchas, but I don't believe there were many (if at all), so I think you will get pretty far by using the standard Ubuntu install guide from the Docker team. Only issue i remember is that systemd still has problems on WSL 2, so I had to manually `service docker start`. – octagon_octopus Mar 30 '22 at 08:20
3

Try starting the docker deamon manually (sudo dockerd) if the sudo docker run hello-world returns Is the docker daemon running?.

McColtney
  • 31
  • 1