Cannot connect to the Docker daemon on macOS

MacosDockerMacos Sierra

Macos Problem Overview

I normally prefer to manage my apps on my OSX with brew

I am able to install docker, docker-compose and docker-machine

docker --version
Docker version 17.05.0-ce, build 89658be
docker-compose --version
docker-compose version 1.13.0, build unknown
docker-machine --version
docker-machine version 0.11.0, build 5b27455

I did not download and run 'Docker for Mac' app.

However when I try to run

> docker run -d -p 80:80 --name webserver nginx
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

I have already checked the sock file

ls -lah /var/run/docker.sock /var/tmp/docker.sock
ls: /var/run/docker.sock: No such file or directory
ls: /var/tmp/docker.sock: No such file or directory

I have also tried this proposed solution:

But I got this error message:

$ eval $(docker-machine env default)
Host does not exist: "default"

Is it possible to get a docker service to run by command line tools?

Macos Solutions

Solution 1 - Macos

On a supported Mac, run:

brew install --cask docker

Then launch the Docker app. Click next. It will ask for privileged access. Confirm. A whale icon should appear in the top bar. Click it and wait for "Docker is running" to appear.

You should be able to run docker commands now:

docker ps

Because docker is a system-level package, you cannot install it using brew install, and must use --cask instead.

Note: This solution only works for Macs whose CPUs support virtualization, which may not include old Macs.

Edit 2022 - It was brought up in the comments section that there has been a licensing change for Docker Desktop. Please consider alternatives below, and check the comments for details.

Solution 2 - Macos

On macOS the docker binary is only a client and you cannot use it to run the docker daemon, because Docker daemon uses Linux-specific kernel features, therefore you can’t run Docker natively in OS X. So you have to install docker-machine in order to create VM and attach to it.

Install docker-machine on macOS

If you don't have docker-machine command yet, install it by using one of the following methods:

  • Using Brew command: brew install docker-machine docker.

  • Manually from Releases page:

    $ curl -L`uname -s`-`uname -m` >/usr/local/bin/docker-machine
    $ chmod +x /usr/local/bin/docker-machine

See: Get started with Docker for Mac.

Install Virtualbox

docker-machine relies on VirtualBox being installed and will fail if this isn't the case. If you already have VirtualBox, you can skip this step.

  • Using Homebrew: brew install --cask virtualbox
  • Manually using the releases on

You will need to actively accept loading the Virtualbox kernel extension in the OS X Security panel and then proceed to restart the machine for the next commands not to fail with Error: VBoxNetAdpCtl: Error while adding new interface

Configure docker-machine on macOS

Create a default machine (if you don't have one, see: docker-machine ls):

docker-machine create --driver virtualbox default

Then set-up the environment for the Docker client:

eval "$(docker-machine env default)"

Then double-check by listing containers:

docker ps

See: Get started with Docker Machine and a local VM.


Solution 3 - Macos

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)

I also answered it here

Solution 4 - Macos

I have Mac OS and I open Launchpad and select docker application. from reset tab click on restart.

Solution 5 - Macos

Try this to create default.

docker-machine create default

Solution 6 - Macos

on OSX assure you have launched the Docker application before issuing

docker ps

or docker build ... etc ... yes it seems strange and somewhat misleading that issuing

docker --version

gives version even though the docker daemon is not running ... ditto for those other version cmds ... I just encountered exactly the same symptoms ... this behavior on OSX is different from on linux

Solution 7 - Macos

I had docker up to date, docker said it was running, and the diagnosis was good. I needed to unset some legacy environment variable (thanks )


Solution 8 - Macos

Install minikube and come join the dark side.

$ bash --version
GNU bash, version 5.0.3(1)-release (x86_64-apple-darwin18.2.0)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>

eval $(minikube docker-env)

$ docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate     -i /local/swagger.json     -l python     -o /local/test/
[main] INFO io.swagger.parser.Swagger20Parser - reading from /local/swagger.json
[main] WARN io.swagger.codegen.DefaultGenerator - 'host' not defined in the spec. Default to 'localhost'.

Works great on Macbook Pro 2018 with bash v5. No need to install all the other docker nonsense these days IMO. The VM and install script that comes with minikube can replace docker machine from my experience.

Solution 9 - Macos

This problem:

$ brew install docker docker-machine
$ docker ps

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

This apparently meant do the following:

$ docker-machine create default # default driver is apparently vbox:
Running pre-create checks...
Error with pre-create check: "VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path"
$  brew cask install virtualbox
$ docker-machine create default 
# works this time
$ docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
$ eval "$(docker-machine env default)"
$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

It finally works.

You can use the “xhyve” driver if you don’t want to install virtual box. Also you can install the “docker app” (then run it) which apparently makes it so you don’t have to run some of the above. brew cask install docker then run the app, see the other answers. But apparently isn't necessary per se.

Solution 10 - Macos

I had the same problem. Docker running but couldn't access it through CLI.

For me the problem was solved by executing "Docker Quickstart". This is located in the "/Applications/Docker/" folder. As long as I work in this instance of the Terminal app Docker works perfectly. If a second window is needed I have to run the "Quickstart" app once more.

I have a Docker for Mac installation. Therefore I am not sure if my solution is valid for a Homebrew installation.

The "Docker Quickstart Terminal" app seems to be essentially some applescripts to launch the terminal app and a bash start script that initialise all the necessary environment variables.

Hope this helps someone else !

Solution 11 - Macos

You should execute script for install docker and launch it from command line:

brew install --cask docker
sudo -H pip3 install --upgrade pip3
open -a Docker
docker-compose ... 

after that docker-compose should work

Solution 12 - Macos

I was facing similar issue on my mac, and I found that docker wasn't running in my machine, I just went to applications and invoked whale and then it worked .

Solution 13 - Macos

This did the trick for me:

open --background -a Docker

Takes some seconds until you can connect to docker.

I am on a Mac OS Big Sur.

Solution 14 - Macos

I first tried docker and docker-compose via homebrew, but it had the problem listed here. I had to install docker's official install from and then everything worked as expected.

Solution 15 - Macos

i simply had to run spotlight search and execute the Docker application under /Applications folder which brew cask install created. Once this was run it asked to complete installation. I was then able to run docker ps

Solution 16 - Macos

Tried the following and its working fine now

$ docker-machine create default
(default) Creating VirtualBox VM...
(default) Creating SSH key...
(default) Starting the VM...
(default) Check network to re-create if needed...
(default) Found a new host-only adapter: "vboxnet0"
(default) Waiting for an IP...
Waiting for machine to be running, this may take a few minutes...
Detecting operating system of created instance...
Waiting for SSH to be available...
Detecting the provisioner...
Provisioning with boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...
Checking connection to Docker...
Docker is up and running!


$ docker-machine env default


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

Solution 17 - Macos

Docker was designed to run on Linux. It can, however, run in a VM on macOS. To do so is a bit of a kludge and that's perhaps why Docker Desktop exists in the first place. But that doesn't mean you can't enjoy using Docker from the comfort of the command line on a Mac.

Some options to consider:

  1. You could use lima and add an alias doocker='lima nerdctl' to your bash profile.
  2. You could install a Linux VM on your machine and use it instead (not recommended).
  3. Dual-boot Linux on Mac. Even machines with the T2 and M1 chips are supported now.

Solution 18 - Macos

With the updated version of VirtualBox (6.1.32r149290), the command docker-machine create --driver virtualbox default doesn't work, there is an error with auto-generated IP for the Virtual VM, explanation is here .

This command helped me to resolve the issue: docker-machine create --driver virtualbox --virtualbox-hostonly-cidr "" default.

Solution 19 - Macos

Just opening Docker Desktop worked for me.

Solution 20 - Macos

I run brew install docker-machine; then the problem is solved. The latest docker version does not have docker-machine included.

Solution 21 - Macos

installing docker-machine was enough for me to solve the problem.


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
QuestionAnthony KongView Question on Stackoverflow
Solution 1 - MacosfriederbluemleView Answer on Stackoverflow
Solution 2 - MacoskenorbView Answer on Stackoverflow
Solution 3 - MacosMaster pView Answer on Stackoverflow
Solution 4 - MacosEhsan BarkhordarView Answer on Stackoverflow
Solution 5 - MacosMossaddeque MahmoodView Answer on Stackoverflow
Solution 6 - MacosScott StenslandView Answer on Stackoverflow
Solution 7 - MacosMichaelView Answer on Stackoverflow
Solution 8 - MacosLigemerView Answer on Stackoverflow
Solution 9 - MacosrogerdpackView Answer on Stackoverflow
Solution 10 - MacosbeoView Answer on Stackoverflow
Solution 11 - MacosBoris AzanovView Answer on Stackoverflow
Solution 12 - MacosRama SharmaView Answer on Stackoverflow
Solution 13 - MacosMattStView Answer on Stackoverflow
Solution 14 - MacosThomas KesslerView Answer on Stackoverflow
Solution 15 - Macoswired00View Answer on Stackoverflow
Solution 16 - MacosmuTheTechieView Answer on Stackoverflow
Solution 17 - MacosvhsView Answer on Stackoverflow
Solution 18 - MacosultraonView Answer on Stackoverflow
Solution 19 - Macosarush436View Answer on Stackoverflow
Solution 20 - MacoshtlbydgodView Answer on Stackoverflow
Solution 21 - MacosahmetbcakiciView Answer on Stackoverflow