Reputation: 40814
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?
Upvotes: 595
Views: 773921
Reputation: 166795
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.
docker-machine
on macOSIf 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.
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.
brew install --cask virtualbox
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
docker-machine
on macOSCreate a default
machine (if you don't have one, see: docker-machine ls
):
docker-machine create --driver virtualbox default
If you get the error Error with pre-create check: "This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory"
, you might need to add the flag --virtualbox-no-vtx-check default
.
docker-machine create --driver virtualbox --virtualbox-no-vtx-check 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:
Upvotes: 297
Reputation: 677
In my case the Terraform provider is looking at the default host ------> unix:///var/run/docker.sock
While my docker desktop running at ------> unix:///Users/$USER/.docker/run/docker.sock
Changing the sock path helped me overcome this problem.
Hint: docker ps
command will give the path at which local instance is runing at. Example:
Cannot connect to the Docker daemon at unix:///Users/$USER/.docker/run/docker.sock. Is the docker daemon running?
Upvotes: 0
Reputation: 493
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 :
Then docker will work properly.
In my case it is working fine.
Upvotes: 8
Reputation: 625
For macOS (Docker Desktop):
Docker Desktop for macOS does not natively support this feature. However, you can use socat, a multipurpose relay, to achieve the same effect.
brew install socat
Run the following command to expose the Docker daemon:
socat TCP-LISTEN:23750,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock &
This command will need to be running as long as you want to access the Docker daemon at tcp://localhost:23750. You may want to set it up as a background service if you need it running all the time.
Upvotes: 0
Reputation: 1067
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.
Upvotes: 15
Reputation: 117
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,
Upvotes: 1
Reputation: 15153
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
Upvotes: 87
Reputation: 469
Input Command = docker ps
Output = Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
If this you facing on your Mac then follow the following steps.
Upvotes: 0
Reputation: 1551
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
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?
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
.
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
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
Upvotes: 147
Reputation: 637
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.
Upvotes: 38
Reputation: 6766
My problem was resolved simply by running the following command on Ventura 13.0
(M2 Pro CPU Architecture), like the command working on Linux Distros:
sudo chown $USER /var/run/docker.sock
Then you should logout from your account or restarting Docker desktop and you can evaluate whether it works properly or not by executing docker ps
command.
Upvotes: 0
Reputation: 947
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.
Upvotes: 2
Reputation: 380
Get the right link from https://www.docker.com/.
Either Intel chip or Mac chip. Then install manually.
It should work fine after that.
Upvotes: 0
Reputation: 314
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.
Upvotes: 2
Reputation: 1217
If you are running into this issue with lima on Mac OSX, check to ensure the docker instance is running using limactl list. In my case the default instance was running but docker was not after a reboot. You may want to add limactl start docker
into your Shell config, e.g. ~/.zshrc
➜ docker ps
Cannot connect to the Docker daemon at unix:///Users/xxxx/.lima/docker/sock/docker.sock. Is the docker daemon running?
➜ limactl list
NAME STATUS SSH VMTYPE ARCH CPUS MEMORY DISK DIR
default Running 127.0.0.1:60022 qemu x86_64 4 4GiB 100GiB ~/.lima/default
docker Stopped 127.0.0.1:50310 qemu x86_64 4 4GiB 100GiB ~/.lima/docker
➜ limactl start docker
...(lima log output)
➜ limactl list
NAME STATUS SSH VMTYPE ARCH CPUS MEMORY DISK DIR
default Running 127.0.0.1:60022 qemu x86_64 4 4GiB 100GiB ~/.lima/default
docker Running 127.0.0.1:50310 qemu x86_64 4 4GiB 100GiB ~/.lima/docker
➜ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Upvotes: 0
Reputation: 483
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:
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.
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.
Upvotes: 2
Reputation: 291
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
Upvotes: 13
Reputation: 10089
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:
alias docker='lima nerdctl'
to your bash profile.Upvotes: 2
Reputation: 2193
QUICK AND SIMPLE
Install Docker Desktop form given url
https://www.docker.com/products/docker-desktop/
Go to setting on top right corner
Upvotes: 0
Reputation: 2193
Install Docker Desktop form given url
https://www.docker.com/products/docker-desktop/
Go to setting on top right corner
Upvotes: 1
Reputation: 1193
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.
Upvotes: 13
Reputation: 2400
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
.
Upvotes: 1
Reputation: 37177
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.
Upvotes: 1042
Reputation: 423
installing docker-machine
was enough for me to solve the problem.
Upvotes: 0
Reputation: 4501
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
Upvotes: 4
Reputation: 66881
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.
Upvotes: 7
Reputation: 28305
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
Upvotes: 11
Reputation: 116
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 .
Upvotes: 3
Reputation: 1822
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.
Upvotes: 10