12

Problem: I am trying to run docker inside vagrant, my Vagrantfile contains following:-

  config.vm.provision "docker" do |d|
     d.run "ubuntu",
       cmd: "bash -l",
       args: "-v '/vagrant:/var/www'"
  end

docker gets installed but when I run any command it gives the error below:-

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I have tried

  1. https://docs.oracle.com/cd/E52668_01/E75728/html/section_rdz_hmw_2q.html

  2. logged in as root into vagrant and started docker still same problem.

  3. tried chmod on /var/run/docker.sock file

nothing seems to work.

output of ps -ef is

/usr/bin/dockerd

docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir 
/var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime docker-runc
girish946
  • 745
  • 9
  • 24
Atul
  • 151
  • 1
  • 2
  • 10
  • 2
    make sure docker service is running or else start it by : sudo service docker start . then try adding sudo to the run command you are executing – shahin Apr 14 '17 at 05:47

6 Answers6

23

Here is what happened to me and what could be a possible solution for someone else. I'm running on Ubuntu 16.04.

I ultimately purged and reinstalled everything from the docker-ce install. I mean everything. Still not working...

Through my internet wizardry I was able to find an article (I can't recall where, there were so many) mentioning that the file located at:

$ sudo nano /etc/systemd/system/docker.service

Had a -d in the place of the daemon at Execstart. That wasn't the case for me. I had ...daemon -D..., but I did notice that it was pointing to /usr/bin/local/docker. That didn't exist, but what does exist is /usr/bin/docker. In that location you will also find docker-containerd, dockerd, etc...

Anyway, I made the change to the docker.service file--simply dropping /local out of there. Saved. Then:

$ systemctl daemon-reload
$ sudo service docker restart
$ sudo service docker status (should see active (running))
$ sudo docker run hello-world

Success!

UkFLSUI
  • 5,509
  • 6
  • 32
  • 47
Bicameral Mind
  • 799
  • 5
  • 9
  • 4
    Your first paragraph here isn't really very 'StackOverflow'-y. Although I'd agree that those sort of answers are annoying in other forums, albeit often the correct solution - too many people just post questions online without attempting to interpret the error message they're seeing - that doesn't happen so much on StackOverflow, and, if people do give those answers, that's what the downvote button is for. – DaveyDaveDave Jul 12 '17 at 06:00
6

On your ssh server, run:

  1. systemctl start docker

  2. systemctl status docker

Docker will start on the server and have a socket on its respective.

kenorb
  • 155,785
  • 88
  • 678
  • 743
Aamir M Meman
  • 1,645
  • 14
  • 15
0

I faced a similar issue, running the command sudo service docker restart, followed by restarting the docker image fixed the issue for me

D_usv
  • 433
  • 7
  • 21
0

Start docker deamon by systemctl start docker.service

Be sure to run command as superuser

Zwenn
  • 5
  • 2
0

i've gotten the same error response. when i checkout the daemon.json file, and i found that

{
     "registry-mirrors": ["http://hub-mirror.c.163.com"]
     "graph": "/etc/docker/mirror"
}

as you can see, i missed "," so i corrected it so simple. how careless i was!

{
     "registry-mirrors": ["http://hub-mirror.c.163.com"],
     "graph": "/etc/docker/mirror"
}

sometimes you need check your code carefully

dream-blue
  • 119
  • 3
0

In my case I had to do:

sudo rm /var/run/docker.pid
sudo docker start [my_container]
colidyre
  • 4,170
  • 12
  • 37
  • 53