Reputation: 6449
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?
Upvotes: 17
Views: 47534
Reputation: 9116
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!
Upvotes: 8
Reputation: 811
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.
Upvotes: 1
Reputation: 1955
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.
Upvotes: 62
Reputation: 249
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.
Upvotes: 7
Reputation: 1671
Before running any Docker command, you need to run the Docker daemon on the host machine:
sudo systemctl start docker
Upvotes: 8