Programmers learn & share
0 votes
307 views

Problem :

I have installed docker-machine 0.1.0 and docker-compose 1.1.0 on my Mac OS 10.8.5.
My Docker-machine is running normally and it can be connected by docker-machine ssh as follows:

$ docker-machine ls

NAME   ACTIVE   DRIVER       STATE     URL                         SWARM

dev    *        virtualbox   Running   tcp://192.168.99.100:2376  

But I am unable to connect from docker-compose.

Getting following error:

$ docker-compose up

Couldn't connect to Docker daemon at http+unix://var/run/docker.sock - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

My Dockerfile and docker-compose.yml are as follows:

Dockerfile

FROM centos:centos7

DOCKER_HOST tcp://192.168.99.100:2376

docker-compose.yml

web:

  build: .

Why can't I connect? Any clues?

by (7.5k points)   | 307 views

2 Answers

0 votes

Solution :

The docker daemon always runs as the root user so you need to write sudo before your Docker command(s).

If you cant use sudo when you use the docker command. Then please create a Unix group called docker and add your users to it. So when the docker daemon starts it will mak the ownership of the Unix socket read or writable by the docker group.

Please follow below steps to create the docker group and add your user to it:

1. Create the docker group by below command.

$ sudo groupadd docker

2. Add your user to the docker group by below command.

$ sudo usermod -aG docker $USER

3. Log out and log back in to it so that your group membership is re-evaluated.

4. Now Verify that you can use the docker commands without the use of sudo by below command.

$ docker run hello-world

This command will download a test image and will run it in a container. When the container runs it prints an informational message and exits.

Further Readings:

https://docs.docker.com/install/linux/linux-postinstall/

by (36.1k points)  
0 votes

The Docker machine is running but you need to export some environment to establish the connection with the Docker machine. By default, the Docker CLI client is trying to communicate to the daenon using http+unix://var/run/docker.sock. Export the correct environment variables using eval and then try again. You can also just run docker-machine env dev to see the environment variables it will see.

Reasons:

There are two possible reasons for this error message;

  • The most common reason is that you are running the command as does not have the permission to access docker.
  • The other reason is that you have not started the docker.

Solutions:

Solution for permission denied:

If you don’t have the permission to access docker, then you can fix this either by running the command as root using sudo since the root has permission to access the docker or adding your user to the docker group.

sudo usermod –a –G docker $USER

After this the user has to log out and log back in completely.

Docket not started:

If you don’t have started docker on Ubuntu, then you can start it by using;

sudo systemct1 enable docker # Auto-start on boot

sudo systemct1 start docker #start right now

 

ago by (2.8k points)  
2,227 questions
2,734 answers
59 comments
241 users