7

My Docker service is up and running. However when attempting to use Docker by running it with sudo, e.g.:

12:40:26/~ $ sudo docker pull fluxcapacitor/pipeline
Using default tag: latest

I have got the following error:

Warning: failed to get default registry endpoint from daemon (Cannot connect to 
the Docker daemon. Is the docker daemon running on this host?). Using system 
default: https://index.docker.io/v1/
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

Note that I had already followed the answers on Mac OS X sudo docker Cannot connect to the Docker daemon. Is the docker daemon running on this host?

as follows:

docker-machine start default

12:40:36/~ $ docker-machine start default
Starting "default"...
Machine "default" is already running.

docker ps

12:41:20/~ $ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

So what more needs to be done?

This is:

$ docker --version
Docker version 1.11.2, build b9f10c9

on El Capitan.

Output of docker-machine env default

$ eval "$(docker-machine env default)"

$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/macuser/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
kenorb
  • 155,785
  • 88
  • 678
  • 743
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
  • Possible duplicate of [Cannot connect to the Docker daemon on macOS](https://stackoverflow.com/questions/44084846/cannot-connect-to-the-docker-daemon-on-macos) – kenorb Apr 08 '18 at 15:26
  • @kenorb Your mistake is discussing on meta https://meta.stackoverflow.com/questions/365735/my-question-was-marked-as-possible-duplicate-even-though-i-had-already-addressed – I am the Most Stupid Person Apr 09 '18 at 09:39
  • Also related: [Docker can't connect to docker daemon](https://stackoverflow.com/q/21871479/55075), the accepted answer got same answer with 'eval' method, but I understand this is for macOS, other for Linux, however it's the same thing in terms of the resolution. – kenorb Apr 09 '18 at 10:07
  • Thanks for the explanation, I've misread your question, as 'Cannot connect to the Docker daemon' error happens when there is the problem with Docker installation, so re-installing it from Cask would potentially help. However in your case, your Docker installation was fine, but the issue was related with `sudo`, so I've clarified your post and retracted the vote. – kenorb Apr 09 '18 at 10:22

4 Answers4

13

The following command exports a few environment variables that the subsequent docker commands use:

eval "$(docker-machine env default)"

However, if you launch docker with sudo, the exported environment variables are not accessible by the docker executable. You could potentially get it to work by passing -E flag to sudo, e.g.:

sudo -E docker pull fluxcapacitor/pipeline

But much easier option is to use docker without root like:

docker pull fluxcapacitor/pipeline
kenorb
  • 155,785
  • 88
  • 678
  • 743
khattam
  • 1,164
  • 1
  • 8
  • 14
2

You have to set environment variables with:

eval "$(docker-machine env default)"

More about it here.

Alexander Guz
  • 1,334
  • 12
  • 31
1

I had same probelem on my MAC, when attempted

# eval "$(docker-machine env default)"

got this error

Error checking TLS connection: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.100:2376": x509: certificate is valid for 192.168.99.101, not 192.168.99.100
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.

to regenerate certificates, find out the docker-machines available;

# docker-machine ls

Output of avalable docker machines (omitted others)

NAME          ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default       -        virtualbox   Running   tcp://192.168.99.100:2376           Unknown   Unable to query docker version: Get https://192.168.99.100:2376/v1.15/version: x509: certificate is valid for 192.168.99.101, not 192.168.99.100

Generate certificates for this default docker-machine

# docker-machine regenerate-certs default

and then setup docker-machine env to default docker-machine;

# eval "$(docker-machine env default)"

and it works normally after that.

khawarizmi
  • 593
  • 5
  • 19
1

I have also tried the same but did not work.

later I have tried these steps on AWS CLI

$ sudo nano /etc/docker/daemon.json
{
"dns": ["8.8.8.8", "8.8.4.4"]
}
$ sudo service docker restart
$ docker pull hello-world