17

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?

7 Answers 7

54

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.

0
16

run with sudo:

sudo docker-compose up -d

2
7

My solution was to simply restart the box (EC2 Amazon Linux2). Chased my tail for 30 mins with permissions and groups, but a simple reboot did the trick.

2
  • Thank you for your sugestion. I was also chasing my tails for hours, and after rebooting the server it started to work. Why any tutorial or readme file don't say to restart?
    – dchang
    Nov 7, 2018 at 17:52
  • Thank god I saw your answer. I spent the last 2 hours trying to figure out what was wrong. Just needed to restart as well. Thanks a tonne. May 23, 2020 at 16:50
6

Before running any Docker command, you need to run the Docker daemon on the host machine:

sudo systemctl start docker
5
  • it is running. I can run any Docker command, like ps, build etc. And i can run docker-compose in another project right now. But when I run only docker-compose in this HTTPD project, I get this error. Jun 22, 2018 at 1:42
  • I see. It is likely a permissions issue then. See here
    – brianolive
    Jun 22, 2018 at 1:49
  • same symptom in a Jenkins environment. docker commands work, but docker-compose failes with the message in the subject. As user jenkins from the CLI I can do all docker commands (via /var/run/docker.sock), but calling docker-compose from the Jenkins job will cause the problem.
    – rhoerbe
    Jun 28, 2018 at 16:57
  • @rhoerbe how did you fix your issue with the Jenkinsfile? Apr 3, 2019 at 22:10
  • On Debian 11 works.
    – EsmaeelE
    Jun 20, 2022 at 7:51
6

I had this, and discovered that my user was not in the docker group, and so didn't have permission.

You can check this by running groups. If docker isn't in the list that's printed, this may be your problem.

You can add your user to the docker group with:

sudo usermod -aG docker yourUserName

After adding my user to the docker group, I had to log out and back in again for the changes to take effect.

EDIT: I did this on a fresh install, and discovered that I needed to reboot before it worked. If you're not sure why it failed, try rebooting!

1

I've had the same error, but in my case it was an invalid docker-compose file: image name was my_app:. E.g

  my_app:
    build:
      context: .
      dockerfile: ./my_app/Dockerfile
    image: my_app:

The error is very unhelpful and took me a long time to figure out, as it was not explicitly written like that in the file, but instead the part after : was an empty variable.

Leaving this here in case someone else stumbles on this issue.

0

for me helped

export DOCKER_HOST=127.0.0.1:2375

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.