Couldn't connect to Docker daemon at http+docker://localhost with docker-compose

Victor Ferreira picture Victor Ferreira · Jun 22, 2018 · Viewed 27.1k times · Source

I have this React app that I want to run on an Apache HTTP Docker container.

So I created a Dockerfile that works with sudo docker build and sudo docker run <name>

FROM httpd:2.4
COPY ./dist/ /usr/local/apache2/htdocs/

I created a docker-compose.yml

version: '3'
services:
  frontend:
    build: .
    ports:
     - "8080:80"
    container_name: frontend

But when I run sudo docker-compose build I get this 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.

What is the problem?

Answer

Max Sherbakov picture Max Sherbakov · Feb 18, 2020

Check your privileges, Following command solved my problem :

sudo chown $USER /var/run/docker.sock

It happens when you try to start docker as non super user and it couldn't get access to it own sockets.