17

I installed docker and there seems to be some issue.

$ docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

$sudo docker ps

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

What should I do?

kenorb
  • 155,785
  • 88
  • 678
  • 743
  • would be nice if you also tell us the version of docker that you are using right now (or how you installed) – Jeffrey04 Jun 07 '16 at 07:22
  • 1
    Possible duplicate of [Docker can't connect to docker daemon](https://stackoverflow.com/questions/21871479/docker-cant-connect-to-docker-daemon) – kenorb Apr 08 '18 at 15:24
  • See also: [Cannot connect to the Docker daemon on macOS](https://stackoverflow.com/q/44084846/55075) – kenorb Apr 08 '18 at 15:25
  • When you use `sudo` by default it doesn't copy the environment in, which environment you apparently need for OS X... – rogerdpack Jul 19 '18 at 18:33
  • This fixes the latest problem: https://stackoverflow.com/questions/74173489/docker-socket-is-not-found-while-using-intellij-idea-and-docker-desktop-on-macos – UserBSS1 Feb 02 '23 at 22:24

8 Answers8

33

You need to set up your shell to use Docker: eval $(docker-machine env default) Where does this command come from? Run docker-machine env default and you'll see something like the following:

$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/eric/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell: 
# eval $(docker-machine env default)

Also you may or may not have to simply start the Docker host beforehand via: docker-machine start default

ericn
  • 12,476
  • 16
  • 84
  • 127
Armin Braun
  • 3,645
  • 1
  • 17
  • 33
9

docker-machine is a legacy stuff for OSX that operates with VirtualBox. What you should do is get rid of it completely, and then you should download the latest version of docker, that is called Docker for Mac

Make sure, you remove the legacy docker, and the docker-machine from your Mac before installing Docker for Mac. If you do not do that, the legacy docker binary will be favoured after the installation, and you will still get the error message, which says that cannot connect to the Docker daemon.

SaWo
  • 1,515
  • 2
  • 14
  • 32
6

I had this same issue I solved it in the following steps:

docker-machine restart

Quit terminal (or iTerm2, etc, etc) and restart

eval $(docker-machine env default)
Master p
  • 826
  • 9
  • 8
4

I just had this problem. I was using the old docker-machine and I switched to the latest docker for mac. Running eval $(docker-machine env default) sets up some environment variables.

To solve my problem, I unset those environment variables...

unset DOCKER_HOST DOCKER_MACHINE_NAME DOCKER_TLS_VERIFY DOCKER_CERT_PATH

grbonk
  • 609
  • 6
  • 22
0

if you are using docker toolbox, type this before running the docker ps command to set the environment

docker-machine env default
lamirap
  • 510
  • 1
  • 3
  • 8
0

to have it persistent on new terminals & reboot put it to the bash_profile file

echo "eval \$(docker-machine env default)" >> ~/.bash_profile
schmichri
  • 514
  • 5
  • 13
0

remove the export DOCKER_HOST.... from your environment (.bashrc, .bash_profile what have you), restart shell/terminal, worked for me.

Aleks Tkachenko
  • 704
  • 7
  • 6
0
  1. Install docker desktop if not installed. (https://docs.docker.com/desktop/install/mac-install/)
  2. Run docker desktop. This will make docker running in the background.
  3. Use docker ps and it will work as expected.
Steev James
  • 2,396
  • 4
  • 18
  • 30