Ubuntu 16.04 - > ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`

UbuntuDocker Compose

Ubuntu Problem Overview


I am getting error on ubuntu 16.04

> "ERROR: Couldn't connect to Docker daemon - you might need to run > docker- machine start default. "

when i run following command

sudo docker-compose up

Can any one answer ?

Ubuntu Solutions


Solution 1 - Ubuntu

assuming your environment variables are set using the following shell command :

eval "$(docker-machine env default)"

then you can find the exact error by running the following shell command:

docker-compose --verbose up -d

many times its a proxy issue or if your running it with charles proxy it can block compose from connecting etc. if it is a proxy issue you can add this to your profile:

export no_proxy=192.168.99.100

Solution 2 - Ubuntu

If you installed Docker as a snap package try this:

sudo snap start docker

Solution 3 - Ubuntu

> Starting the Docker daemon

Use following command :

sudo systemctl start docker  

or on older distributions, you may need to use:

sudo service docker start

Solution 4 - Ubuntu

You should add your user in docker group. And then, you can use docker command without 'sudo'.

$ sudo usermod -aG docker ${USER}
$ sudo service docker restart

Next, you have to logout in your OS. Finally, when you login, you can use docker command without 'sudo'.

Solution 5 - Ubuntu

You don't need to think much. Run the command with sudo previlage.

sudo docker-compose up -d --build

Solution 6 - Ubuntu

After

#sudo snap remove docker //only if required
sudo snap install docker

Following command worked for me

docker-compose --verbose up -d

In case docker service is not active, please do any of the following (give priority to first one)

1. sudo snap start docker    
2. sudo systemctl start docker
3 .sudo service docker start

Solution 7 - Ubuntu

After installing can execute command to have access to docker functionality without sudo. In my sitation, with same errors all is resolved after :

$ sudo usermod -aG docker ${USER}
$ su - ${USER}
$ id -n
$ sudo usermod -aG docker username

and can restart docker after that:

systemctl restart docker

Solution 8 - Ubuntu

Running $sudo docker compose up -d resolved my issue. Actually mine is permissions issue which I came to know by providing verbose option.

Solution 9 - Ubuntu

We need to restart the docker

$ sudo service docker restart

click here

Solution 10 - Ubuntu

Try running with root: sudo docker-compose build

Solution 11 - Ubuntu

Sometimes, this error appears if you built stack before. Reason of giving error is migh be file permissions. If in building process docker generates new files or edits some files, there will be some root owned files.

So, if the reason is permissions, make your user the owner of all application files.

$ sudo chown -R ${USER} .

Solution 12 - Ubuntu

I had this same error 10 minutes ago and solved it by doing:

sudo snap remove docker

when finished:

sudo snap install docker

Problem solved.

Solution 13 - Ubuntu

Use "sudo" privilege as prefix in all of your 'docker-compose' terminal commands.

Solution 14 - Ubuntu

in my case , sometime you just need to use "sudo docker-compose up"

Solution 15 - Ubuntu

I was also facing this

asif@ck ~/u/m/moberry_pizza_order (main)> docker-compose -f local.yml build
ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.
asif@ck ~/u/m/moberry_pizza_order (main) [1]> docker-machine start default
Docker machine "default" does not exist. Use "docker-machine ls" to list machines. Use "docker-machine create" to add a new one.
asif@ck ~/u/m/moberry_pizza_order (main) [1]> docker-machine ls
NAME   ACTIVE   DRIVER   STATE   URL   SWARM   DOCKER   ERRORS
asif@ck ~/u/m/moberry_pizza_order (main)> docker-machine create -d dev;
Driver "dev" not found. Do you have the plugin binary "docker-machine-driver-dev" accessible in your PATH?
asif@ck ~/u/m/moberry_pizza_order (main) [1]> docker-compose -f local.yml up
ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.

Then I tried following,

$ sudo apt update && sudo apt dist-upgrade
$ docker-compose --version
docker-compose version 1.25.5, build unknown
$ sudo usermod -aG docker $USER
$ newgrp docker
$ docker run hello-world

Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world b8dfde127a29: Pull complete Digest: sha256:f2266cbfc127c960fd30e76b7c792dc23b588c0db76233517e1891a4e357d519 Status: Downloaded newer image for hello-world:latest

Hello from Docker! This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.
  2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
  3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
  4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.

To try something more ambitious, you can run an Ubuntu container with:

 $ docker run -it ubuntu bash

After doing those my command start working

 $docker-compose -f local.yml up

Creating network "moberry_pizza_order_default" with the default driver Creating volume "moberry_pizza_order_local_postgres_data" with default driver Creating volume "moberry_pizza_order_local_postgres_data_backups" with default driver Building postgres Step 1/4 : FROM postgres:13.2 13.2: Pulling from library/postgres

So restarting the daemon is the main thing here. you can do it several ways.

Solution 16 - Ubuntu

I noticed that I got this error after installing docker-compose. Trying to runsudo docker-compose build gave me the error --

> ERROR: Couldn't connect to Docker daemon. You might need to install Docker

I solved this by installing docker-ce (Ubuntu 16.04 and 18.04). Everything worked as expected thereafter

Solution 17 - Ubuntu

In my particular case the mysql service specified in my docker-compose.yml file had created a volume named mysql_data in the project root directory. The problem is that this directory, and the contained files had been created with the user 999, and group of docker. So, we have essentially created ourselves a permissions issue which can be mitigated all together by using the techniques discussed in Handling Permissions With Docker Volumes

To remedy the immediate situation, however, you should determine what volume's data is causing the issue. In my particular case it was the mysql_data volume, so I executed the following, in the project root directory, to change file and directory ownership to that of the currently logged in user:

sudo chown -R ${USER}:${USER} mysql_data

If you are unsure which volume is causing the ownership related issue, to ensure that all of your project's ownership details are the same, you should execute the following in your project root directory:

sudo chown -R ${USER}:${USER} .

Now, if your project is under Git source code control, as a result of executing one of the above commands, you will now have a situation whereby file and directory ownership differs to that of the ownership in git stored objects database. You will most likely encounter errors similar to, "git: Unable to index file", in which case - prior to the further adding and committing of any files to your git project repository, you should ensure that the ownership of the files in the git objects database are an exact mirror of your project's file ownership. You can ensure this by executing the following in the project root:

sudo chown -R ${USER}:${USER} .git/objects

Having now fixed the initial errors you encountered, you can now issue your original docker-compose command, that originally resulted in the "Couldn't Connect to Docker Daemon" error, successfully.

Solution 18 - Ubuntu

My issue was that I was missing $ sign in front of variable in the image name

image: imagename:{TAG:-develop-latest}

Solution 19 - Ubuntu

If you are on Windows 10 and using Docker Toolbox use this

& "C:\Program Files\Docker Toolbox\docker-machine.exe" env | Invoke-Expression

Solution 20 - Ubuntu

I had this error and did the unthinkable: I just rebooted my laptop. I was and am annoyed about it, but it took about 1 minute and it worked.

Solution 21 - Ubuntu

If you installed docker from the snap store , you can start docker this way

sudo snap start docker

and then try this :

 sudo docker-compose up

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKundan royView Question on Stackoverflow
Solution 1 - Ubuntuj2emanueView Answer on Stackoverflow
Solution 2 - UbuntuMedhat GayedView Answer on Stackoverflow
Solution 3 - UbuntuKundan royView Answer on Stackoverflow
Solution 4 - Ubuntuhyung jun yooView Answer on Stackoverflow
Solution 5 - UbuntuashiqueView Answer on Stackoverflow
Solution 6 - UbuntuSamiView Answer on Stackoverflow
Solution 7 - UbuntuVencendorView Answer on Stackoverflow
Solution 8 - Ubuntusrikanth chitturiView Answer on Stackoverflow
Solution 9 - UbuntuSaya KastaView Answer on Stackoverflow
Solution 10 - UbuntuShashank SaxenaView Answer on Stackoverflow
Solution 11 - UbuntuserhatcileriView Answer on Stackoverflow
Solution 12 - UbuntuJoelBonetRView Answer on Stackoverflow
Solution 13 - UbuntuZekarias Taye HirpoView Answer on Stackoverflow
Solution 14 - UbuntumikeView Answer on Stackoverflow
Solution 15 - UbuntuauvipyView Answer on Stackoverflow
Solution 16 - UbuntuIvan_ugView Answer on Stackoverflow
Solution 17 - UbuntuMatt GView Answer on Stackoverflow
Solution 18 - UbuntuMistyKView Answer on Stackoverflow
Solution 19 - UbuntuKalView Answer on Stackoverflow
Solution 20 - UbuntumlissnerView Answer on Stackoverflow
Solution 21 - UbuntuMacdonaldView Answer on Stackoverflow