562

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: Mac OS X sudo docker Cannot connect to the Docker daemon. Is the docker daemon running on this host?

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?

3
  • 21
    Launch the Docker application from Launchpad, will be showing a dialog asking that for run the App, is necessary granted some privileged for this App, after this, the Docker is back to the game. Commented Jan 22, 2018 at 0:19
  • In my case there was another user loggedin thats why it was failing. Logout other user and worked then
    – Raza Ahmed
    Commented Jun 14, 2019 at 17:33
  • This should be main and bolded comment @RafaelKerr Commented Apr 1 at 12:11

39 Answers 39

1018
+100

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.

25
  • 30
    This should be the accepted answer. Go to the launch pad after install and search docker
    – Joe Lloyd
    Commented Aug 14, 2017 at 8:24
  • 75
    I did a brew install docker and the app wasn't installed until I ran the command brew cask install docker. Thanks!
    – jbrahy
    Commented Sep 12, 2017 at 21:09
  • 4
    What happens if the command still doesn't work even after the cask install (and Docker whale shows it's running after password given)?
    – vol7ron
    Commented Mar 19, 2018 at 3:13
  • 7
    This is great and all; but is there no way to do this without getting into the GUI? $ open /Applications/Docker.app returns LSOpenURLsWithRole() failed with error -10810 for the file /Applications/Docker.app.
    – dlamblin
    Commented Mar 5, 2019 at 13:45
  • 8
    @friederbluemle docs.docker.com/desktop/mac/release-notes/#new references a new licensing model which requires organizations over a certain size to pay to use the GUI on Mac and Windows. The answer should really be more like stackoverflow.com/a/49719638/442837. I also wrote about problems on bigsur here mindhaus.medium.com/…
    – dres
    Commented Sep 2, 2021 at 17:41
284

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 https://github.com/docker/machine/releases/download/v0.16.1/docker-machine-`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 Virtualbox.org

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.


Related:

15
  • 31
    this should be the accepted answer. It clearly outlines a) why it doesn't work, b) instructions to get it working without downloading the UI on OSX and c) reference links for further reading. Commented Jun 20, 2019 at 5:51
  • 3
    If you are on MacOS and using Virtualbox >=6.1.28 and you are receiving an error along the lines of: VBoxManage: error: Code E_ACCESSDENIED (0x80070005) - Access denied (extended info not available) VBoxManage: error: Context: "EnableStaticIPConfig(Bstr(pszIp).raw(), Bstr(pszNetmask).raw())" at line 242 of file VBoxManageHostonly.cpp Then check out this answer Commented Dec 1, 2021 at 21:18
  • 17
    Docker machine is now deprecated, it should be outlined in the answer docs.docker.com/machine
    – lvndry
    Commented Dec 16, 2021 at 9:23
  • 10
    Also it is not possible to install Virtualbox on ARM Macs... And as far as I can tell is not very likely to be possible. Basically it will support only ARM guest OSes (which is not terrible) or it has to emulate an Intel CPU which most likely will work awful.
    – skaurus
    Commented Jul 22, 2022 at 13:35
  • 2
    on osx 12.4 (monterey) got stucked here : docker-machine create --driver virtualbox default Running pre-create checks... Error with pre-create check: "This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory"
    – nicolas
    Commented Jul 6, 2023 at 16:25
134

If you wound up here after Docker Desktop 4.13.0 like me, it's because Docker got rid of the /var/run/docker.sock symlink in default behavior! See release notes here.

Quick fix: copy the command under "Permanent Solution" below

The Problem

I was experiencing docker ps (and other docker client commands) working, but other libraries that interact with docker (such as supabase CLI) resulted in:

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

Solution

Now, you have to do something manual in order to get your tools to find the real docker socket file, which by default is at ~/Library/Containers/com.docker.docker/Data/docker.raw.sock.

Permanent Solution: Manually Symlink

This is a permanent solution that "undoes" this temporary fix.

sudo ln -s ~/Library/Containers/com.docker.docker/Data/docker.raw.sock /var/run/docker.sock
DOCKER_HOST=unix:///var/run/docker.sock docker ps # test that it works using linked socket file

Temporary Solution: Use DOCKER_HOST

This will temporarily get your command to use the new socket file

DOCKER_HOST=unix:///Users/$USER/Library/Containers/com.docker.docker/Data/docker.raw.sock docker ps

(replacing docker ps with whatever command you'd like, such as supabase start)

You can also make it work in your current terminal session, or paste into your .zshrc for always, with:

export DOCKER_HOST=unix:///Users/$USER/Library/Containers/com.docker.docker/Data/docker.raw.sock
13
  • 19
    This is the only answer that helped me on my M1 mac. Commented Oct 22, 2022 at 17:15
  • 1
    Great answer! maybe you should transform it into a new question for all those who recently installed supabase and encounter this error 👍
    – Manu
    Commented Oct 27, 2022 at 15:57
  • 1
    Thanks a lot. I was getting "Cannot connect to the docker daemon at unix:///var/run/docker.sock. is the docker daemon running? (Details: [2] No such file or directory)" since I set up a fresh installation of Ventura and Docker. This gave me headache the whole day. I was about to give up when I stumbled over your answer. You should definitely transform this to a new question. Thx a lot. Commented Oct 28, 2022 at 13:58
  • Thanks a lot! However, if someone else came here like me because of this issue in IntelliJ etc. then it's better to fix this in IntelliJ directly, see stackoverflow.com/a/74175227 Commented Oct 29, 2022 at 12:24
  • 2
    Hey folks! This should have been addressed in 4.13.1, so you shouldn't need to manually create the symlink anymore! If you're still experiencing this, I would recommend updating Docker and see if it resolves itself. docs.docker.com/desktop/release-notes/#4131
    – efriis
    Commented Apr 24, 2023 at 18:51
69

ATTN: docker-machine is deprecated (see here)

The docker-machine project has now been officially laid to rest.

I found Colima to be a great replacement and you can easily connect the docker daemon with a simple steps:

brew install docker docker-compose colima
# make coffee
colima start

Ready to docker:

docker run hello-world
7
  • 5
    Thanks a bunch! I tried the other answers here but this is the only solution that worked for my M1 Pro oO. Finally, I am able to docker httpbin without installing the app :) Commented Dec 7, 2022 at 19:30
  • 1
    The only answer that helped me and gave extra coffee.
    – Vassily
    Commented Apr 27, 2023 at 16:13
  • 3
    Was the only answer that helped me with a MacOS M2 chip. Thank you.
    – Star
    Commented May 9, 2023 at 9:05
  • it was the coffee, right? Commented May 9, 2023 at 9:45
  • 1
    This is really helped me!! Commented Mar 10 at 5:14
51

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

3
  • 2
    The eval one "should" be all you need :)
    – rogerdpack
    Commented Jul 19, 2018 at 18:31
  • 4
    I get -bash: docker-machine: command not found.
    – joachim
    Commented Feb 18, 2022 at 9:32
  • 1
    docker machine is deprecated, the repo is locked
    – J'e
    Commented Jun 15, 2022 at 15:02
40

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

3
  • 3
    Yes, you have to launch the Docker application first haha
    – Ender
    Commented Nov 18, 2019 at 16:00
  • This one is a common failure among specialists, no sarcasm.
    – coffekid
    Commented Apr 16 at 15:17
  • In my case, it was a fresh install and I had to go to the Docker app, sign in (or continue w/o signing in), set it up and then it was good to go!
    – bqubique
    Commented Jun 30 at 7:38
35

For me Re-starting docker, didn't help. (Tried with both through terminal and UI)

The below option was unchecked, so I made it checked. After this I was able to run my container Setting -> Advanced -> Enabled default Docker socket(Requires Password)

Note - It will require admin Credentials.

enter image description here

3
  • This fixed my issue in Rubymine with the latest version of Docker for the error. Thank you! Commented May 25, 2023 at 15:07
  • fixed the issue for me as well running on MacOs Commented Aug 1, 2023 at 8:40
  • 1
    I was about to post this solution, thanks pal! Commented Nov 16, 2023 at 19:43
18

Try this to create default.

docker-machine create default
5
  • 5
    this just gave me ... docker-machine create default Creating CA: /Users/stens/.docker/machine/certs/ca.pem Creating client certificate: /Users/stens/.docker/machine/certs/cert.pem Running pre-create checks... Error with pre-create check: "VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path" .... which seems wrong since VirtualBox no longer is necessary to run docker on osx Commented Jun 6, 2017 at 0:54
  • Appears you can use xhyve as well, see stackoverflow.com/a/42419979/32453 or just install virtualbox :)
    – rogerdpack
    Commented Jul 19, 2018 at 18:02
  • And.. so what ?
    – FrankyFred
    Commented Oct 26, 2018 at 17:03
  • 1
    @FrankyFred OK I added an answer to attempt to clarify.
    – rogerdpack
    Commented Sep 21, 2020 at 19:38
  • docker machine is deprecated. the repo is locked.
    – J'e
    Commented Jun 15, 2022 at 15:03
13

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.

4
  • 1
    Unable to find application named 'Docker'
    – alper
    Commented Apr 15, 2022 at 16:33
  • @alper I am not sure if it is relevant. I am on a Mac OS Big Sur. I included that in my answer.
    – MattSt
    Commented May 6, 2022 at 10:08
  • 1
    Docker app should be installed firstly with brew install --cask docker Commented Feb 27, 2023 at 10:19
  • it doesn't work even installing using brew install --cask docker: ``` Unable to find application named 'Docker' ```
    – Sixro
    Commented Jun 24 at 8:37
13

To extend other answers - after spending all morning on this exact issue and none of the other answers helped, finally I discovered that docker was trying to access the wrong path for docker.sock (!!) because some months ago I installed colima.

Running this helped me switch back:

docker context use default

2
  • 1
    I think this is what did it for me as well - I also had installed Colima a while back. But I needed to restart Docker and open a new terminal. Not sure both necessary, but it's working now. Thanks! Commented May 30, 2023 at 10:22
  • This did the trick for me. After switching back to Docker Desktop from Orbstack.
    – Chiel
    Commented Mar 6 at 19:23
11

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

10

Install minikube and come join the dark side.

https://kubernetes.io/docs/tasks/tools/install-minikube/

$ 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 <http://gnu.org/licenses/gpl.html>

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.

4
  • As a follow up comment, I needed docker as well for another project w/o kube and the docker desktop works great. Just don't start it up always or else kube gets angry from this post.
    – akahunahi
    Commented Apr 24, 2019 at 19:41
  • minikube and eval $(minikube docker-env) does not resolve the issue for me.
    – Ian Smith
    Commented Dec 10, 2021 at 0:04
  • Is Docker Desktop installed? Try using Wireshark to view the packets and connections. The env command will show the environment variables. That should give some insights on the macos networking layers. With minikube, the Kaniko builder is likely a better solution come 2022.
    – akahunahi
    Commented Jan 15, 2022 at 23:00
  • I am using minikube instead of docker desktop and this worked for me. Commented Oct 17, 2023 at 4:24
10

Just opening Docker Desktop worked for me.

2
  • 5
    Docker Desktop now requires a paid subscription for commercial use
    – J'e
    Commented Jun 15, 2022 at 14:59
  • 1
    This was the solution for me Commented Feb 12, 2023 at 1:41
10

In my case, MacOS asked me to give docker access to run the default socket. I cancelled by mistake. However, in the advanced settings section I found the setting. After checking it and restarting docker, the permission issue got resolved.

enter image description here

enter image description here

1
  • Ding! Ding! Ding! We have a winner!!! I wish this answer was at the top; it's such an easier thing to check for than the top answers. It fixed my issue, thank you!!!
    – Keith
    Commented Jan 19 at 19:54
7

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 https://docs.docker.com/docker-for-mac/troubleshoot/#workarounds-for-common-problems )

unset DOCKER_HOST
unset DOCKER_CERT_PATH
unset DOCKER_TLS_VERIFY
2
  • 1
    this fixed my issue after an update from VM based docker to the Mac Installer. It kept looking for the VM.
    – bobomoreno
    Commented Jul 25, 2018 at 16:30
  • 1
    use this if you see a wrong IP address in 'Cannot connect... etc'
    – bobomoreno
    Commented Nov 24, 2018 at 17:09
7

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.

5

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

For me the problem was solved by executing "Docker Quickstart Terminal.app". 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 !

4

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

0
4

If you are getting this error in new mac book pro m1 chip. docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

So, Let me tell you docker has changed something in latest release so you can read the official page also : https://docs.docker.com/desktop/install/mac-install

After downloading the docker.dmg file

After that run this in terminal :

  1. softwareupdate --install-rosetta
  2. sudo hdiutil attach Docker.dmg
  3. sudo /Volumes/Docker/Docker.app/Contents/MacOS/install
  4. sudo hdiutil detach /Volumes/Docker

Then docker will work properly.

In my case it is working fine.

1
  • Thanks mate!! This worked!! Although I had to uninstall Docker first and run these commands first - rm -rf Library/Group\ Containers/group.com.docker; rm -rf Library/Containers/com.docker.docker; rm -rf Library/Application\ Support/Docker\ Desktop Commented May 1 at 12:07
3

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 .

2

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 docker='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.
2

The one hack which always works for me even on Mac Ventura 13.3.1 is

stop docker

Remove docker sock

sudo rm /var/run/docker.sock

Start docker again.

0
1

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 https://stackoverflow.com/a/69745931/2917630 .

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

1

Install Docker Desktop form given url

https://www.docker.com/products/docker-desktop/

Go to setting on top right corner

  • Goto General
  • Tick on Start Docker Desktop when you login you
1

I had the similar problem. And probably my particular case/solution can help others also.

Prerequisites:

I have MacOS (M1 chip) and installed Docker App. Docker Engine v20.10.23.

In my particular case I've tried to run spring-boot:build-image command in Maven with IntelijIdea to make a Docker Image for a service.

In response I had - [2] No such file or directory

And in IntelijIdea console I had - [INFO] I/O exception (java.io.IOException) caught when processing request to {}->docker://localhost:2376: com.sun.jna.LastErrorException: [2] No such file or directory

So, initially, I run in Mac terminal docker ps . It returned "Cannot connect to the Docker daemon at tcp://localhost:2376. Is the docker daemon running?"

Solution:

So I followed the next steps, as advised in another comments:

  1. run in terminal brew install --cask docker From the @friederbluemle answer above the explanation is next: "Because docker is a system-level package, you cannot install it using brew install, and must use --cask instead."

I suppose that initially I installed Docker with brew install, so probably it was the part of this issue.

  1. run Docker App
  2. run in terminal export DOCKER_HOST=unix:///var/run/docker.sock

After that when I run in terminal docker ps , it returned table columns CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES and command spring-boot:build-image works fine.

1
  • Thanks @rsnlpn, i added export DOCKER_HOST=unix:///var/run/docker.sock in my .zshrc and done! Commented Apr 19, 2023 at 16:08
1

Another solution for me (on the Apple Silicon) was to install rancher or Podman, but Podman has some issues while importing the libraries (i.e. paho_mqtt for Rust).

brew install rancher

Then starting the App and choose the service to start the VM.

1
  • 1
    This is the answer for me - can't use docker Desktop due to licensing concerns.
    – Ishmael7
    Commented Mar 29, 2023 at 13:46
1

I got a similar case in MacOS docker desktop, that PHPStorm is not recognizing any container and report socket not found or docker is not running. I found in docker app => settings => advanced => checkbox : Allow default Docker socket to be used. After I check this and restart docker app, it works okay. Just a tip for docker beginners like me. Thanks,

0

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 https://docs.docker.com/docker-for-mac/install/ and then everything worked as expected.

0

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

0

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!

Then

$ docker-machine env default

Finally

$ eval $(docker-machine env default)
$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
1
  • docker machine is deprecated. the repo is locked. The last update was more than 3 years ago
    – J'e
    Commented Jun 15, 2022 at 15:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.