Docker - How to fix 'ERROR Couldn't connect to Docker daemon' Error

I faced this error when i use docker-compose for web development in Ubuntu 18.04.

$ docker-compose up -d
ERROR: Couldn\'t connect to Docker daemon at http+docker://localunixsocket - is it running?

It can happen if docker is not running or it dosen't have proper permissions to run. or your user is not in the docker group.

Docker is running?

you can see if docker is running with the sudo service docker status command. "Active" means "running".

$ sudo service docker status
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-06-11 17:25:04 KST; 8min ago
     Docs: https://docs.docker.com
 Main PID: 19093 (dockerd)
    Tasks: 12
   CGroup: /system.slice/docker.service
           └─19093 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
....

The sock file of docker has proper permissions?

Type ls -la /var/run/docker.sock command in the terminal. you can see the permission of docker.sock. the owner should be 'root' and the group should be 'docker'.

$ sudo ls -la /var/run/docker.sock
srw-rw---- 1 root docker 0 Jun 11 17:25 /var/run/docker.sock

Is your user in docker group?

If both above are set correctly, it might happens because of "docker group". a user which runs docker have to belong to "docker group". If not, you have to run it by root user.

Type below command to add the current user to "docker group"

$ sudo usermod -aG docker ${USER}

You should logout and login or reboot.

참고

codechachaCopyright ©2019 codechacha