Docker command not found when running on Mac
Asked Answered
S

23

106

I'm trying to run the below code as instructed in the docker-graphite-statsd:

docker run -d\
 --name graphite\
 --restart=always\
 -p 80:80\
 -p 2003-2004:2003-2004\
 -p 2023-2024:2023-2024\
 -p 8125:8125/udp\
 -p 8126:8126\
 graphiteapp/graphite-statsd

It gives this error:

$ sudo docker run -d --name graphite --restart=always -p 80:80 -p 2003-2004:2003-2004 -p 2023-2024:2023-2024 -p 8125:8125/udp -p 8126:8126 graphiteapp/graphite-statsd
sudo: docker: command not found

This is on a Mac. I tried brew install docker but it made no difference.

How do I resolve this?

Sunburst answered 22/9, 2020 at 11:49 Comment(7)
Follow steps from official site : docs.docker.com/docker-for-mac/installCynthla
Run brew doctor it'll help you to detect the error in the installation.Uball
I installed it from the official link for my new M1 and the terminal can't find the docker command. Anyone else with this issue? https://docs.docker.com/docker-for-mac/install/ the brew doctor didn't help.Huggermugger
it does work just fine on the app, it seems to be running my container if I do it from there, just not from the terminal zsh on my mac m1Huggermugger
see my answer to fix the issue if your terminal can't find the command: #64009638Huggermugger
If you installed the .dmg package on Mac, make sure that you opened the docker desktop app and grant the required privileges and permissions to it, once, before running the docker command.Pentavalent
Docker on Mac is such a pain in the you-know-where...Adur
D
11

Run brew list which will show a list of all your installed Homebrew packages.

But it's highly recommended to install docker using below link on your mac :

https://docs.docker.com/docker-for-mac/install/

Doretha answered 22/9, 2020 at 12:42 Comment(5)
I did install from the link (no brew) and it still can't find the command!?Huggermugger
For me, the docker command didn't become available until I ran the Docker desktop app. Simply following the .dmg's instructions to copy Docker into the Applications folder wasn't enough. In other words, you'll have to actually run Docker to complete the installation process.Repel
@CalebKoch I've run the Docker Desktop app, and still no docker command.Orndorff
Can't run the desktop app because I literally don't have a desktop. How can this be done in the shell (ssh)?Optional
I still can't make this work as it used to (the docker CLI becomes available only when you're running Docker Desktop). I've uninstalled and reinstalled now many times in a row, via both the Homebrew cask and the downloaded dmg from the Docker website. All I can think is that something isn't getting cleaned up to the point that reinstallation takes care of enabling the CLI as part of app startup. As a workaround, I just did echo PATH="$PATH:$HOME/.docker/bin", and now I can run docker commands. I suppose they'll fail if Docker Desktop isn't also running.Teddman
R
212

I'm afraid you need to add docker command to your PATH manually. It can be done through profile file. As ZSH is now a default shell on MacOS, it would go to ~/.zprofile file:

# Add Visual Studio Code (code)
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
# Add Docker Desktop for Mac (docker)
export PATH="$PATH:/Applications/Docker.app/Contents/Resources/bin/"
Randolphrandom answered 19/4, 2022 at 11:9 Comment(6)
That's the only solution here. Thank you!Underage
Note that recent versions of docker install the CLI in $HOME/.docker/bin, and these are just symlinks to the bins in /Applications/Docker.app/Contents/Resources/bin/Lieutenancy
Be sure to add the /Applications/Docker.app/Contents/Resources/bin/ in ~/zshrc or bashrc. I was adding it with an EXPORT command but that only set the PATH for my current terminal session.Butene
That's the solution which fixed it after visiting more than 10 links in internet. ThanksShiau
Why this answer is still not considered as accepted answer? The solution works great.Fussy
and then run "exec zsh" to activate the changes.Preparatory
Z
39

After installing docker using Homebrew, start the Docker daemon by searching for Docker in the Application folder in Finder and running it.

I had to run the following from terminal after doing the above: docker run -d -p 80:80 docker/getting-started

Now run "docker --version" from terminal and it should give the desired result.

Reference : https://www.cprime.com/resources/blog/docker-on-mac-with-homebrew-a-step-by-step-tutorial/

Zumstein answered 21/1, 2021 at 7:26 Comment(1)
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?Optional
K
36

There's is likely a better solution but this worked for me (macOS):

Edit your .zshrc or .bashrc, depending on which one you use

vi ~/.zshrc # or ~/.bashrc

In my case .zshrc

# ~/.zshrc
...

alias docker="/Applications/Docker.app/Contents/Resources/bin/docker"

...
source ~/.zshrc

this should work now

docker --version

This works because we're aliasing docker to the executable located in /Applications/Docker.app/Contents/Resources/bin/docker.

Karl answered 11/12, 2022 at 6:11 Comment(2)
Instead of an alias, I'd use a symlink so scripts can also find it. eg: ln -s /Applications/Docker.app/Contents/Resources/bin/docker ~/bin/Orndorff
From Docker Desktop version 4.18, default "CLI utility" installation PATH is $HOME/.docker/bin, than instead of using /usr/local/bin/docker, you must use export PATH=$PATH:$HOME/.docker/bin, and it worked. Docker made this change because installing "CLI" to the /usr/local/bin PATH required root permissions.Brycebryn
D
17

export PATH="$PATH:/Applications/Docker.app/Contents/Resources/bin/"

is the only solution works for me

Tried the export PATH="$PATH:$HOME/.docker/bin" but failed, although it's the symlink to real location and I can run docker from it in Terminal

Dowable answered 28/4, 2023 at 20:15 Comment(2)
Laptop OS is Mac 13.3.0Dowable
it 's on so work for me on Mac Montery. thanksPugh
N
15

By default Docker CLI tools are installed under $HOME/.docker/bin You need to manually add $HOME/.docker/bin to your PATH .

You can change this by going to Docker --> Settings --> Advanced --> change from user to system After choosing system Docker CLI tools are installed under /usr/local/bin.

This is persistent method and you won't have to export.

If you don't want to change settings, exporting this in the terminal where docker will be used does the did.

export PATH="$PATH:/Applications/Docker.app/Contents/Resources/bin/"
Nickolai answered 17/8, 2023 at 8:21 Comment(1)
every time Docker has a new update, you need to run this code to re-add to the path somehow for me on my Mac.Migrant
D
11

Run brew list which will show a list of all your installed Homebrew packages.

But it's highly recommended to install docker using below link on your mac :

https://docs.docker.com/docker-for-mac/install/

Doretha answered 22/9, 2020 at 12:42 Comment(5)
I did install from the link (no brew) and it still can't find the command!?Huggermugger
For me, the docker command didn't become available until I ran the Docker desktop app. Simply following the .dmg's instructions to copy Docker into the Applications folder wasn't enough. In other words, you'll have to actually run Docker to complete the installation process.Repel
@CalebKoch I've run the Docker Desktop app, and still no docker command.Orndorff
Can't run the desktop app because I literally don't have a desktop. How can this be done in the shell (ssh)?Optional
I still can't make this work as it used to (the docker CLI becomes available only when you're running Docker Desktop). I've uninstalled and reinstalled now many times in a row, via both the Homebrew cask and the downloaded dmg from the Docker website. All I can think is that something isn't getting cleaned up to the point that reinstallation takes care of enabling the CLI as part of app startup. As a workaround, I just did echo PATH="$PATH:$HOME/.docker/bin", and now I can run docker commands. I suppose they'll fail if Docker Desktop isn't also running.Teddman
T
9

This command helped me:

/Applications/Docker.app/Contents/Resources/bin/docker --version

Check version after that:

docker --version
Tempt answered 15/4, 2022 at 9:7 Comment(2)
ec2-user@ip-xxx-xxx-xxx-xxx ~ % docker --version returns Docker version 20.10.23, build 7155243 but I still can't run anything docker run hello-world or docker ps only results in Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?Optional
I added /Applications/Docker.app/Contents/Resources/bin to the $PATH after confirming this command workedSupercilious
L
9

As of docker desktop mac (in my case v4.18, Apple Silicon version), the default installation is

  • no longer => /usr/local/bin
  • now => $HOME/.docker/bin

See Docker Desktop > Settings > Advanced, which provides two options:

  • System, and
  • User, with User being default

In the case of System, the location is in the default macOS path. In the case of User, you'll need to add an entry to your path.

System: (Requires password) Docker CLI tools are installed under /usr/local/bin.

User: Docker CLI tools are installed under $HOME/.docker/bin. Note: You need to manually add $HOME/.docker/bin to your PATH.

Lieutenancy answered 15/4, 2023 at 16:0 Comment(0)
C
6

You'll have to add it to your path. If your shell is bash, here are the steps you need to take:

nano ~/.bash_profile

then, add your Docker binary path (mine there, for example):

export PATH="$PATH:/Applications/Docker.app/Contents/Resources/bin/"

then reload the configuration & test with:

source ~/.bash_profile && docker --v

Hope this helps!

Covered answered 25/4, 2023 at 1:1 Comment(0)
I
6

With the new version Docker Desktop 4.21.1, by default the desktop app engine (Macos) will setup Docker in /Applications/Docker.app/Contents/Resources/bin/docker but this location can be changed by the advance settings

  1. Change the advance settings from user to System (this will change the location to /usr/local/bin)
  2. Run the command docker --version

enter image description here

Ial answered 28/7, 2023 at 10:13 Comment(0)
H
5

Homebrew's docker doesn't install /usr/local/bin/docker or the /Applications/Docker.app any more on 10.13.

You have to download the Docker Desktop for Mac application from the docker.com site above and install it.

Hardboard answered 12/10, 2021 at 21:7 Comment(3)
I did install from the link/official site (no brew) and it still can't find the command!?Huggermugger
This is no longer true. ´´´brew install --cask docker´´´ does indeed install docker to /usr/local/bin/docker and does make a Docker application in /ApplicationsZuniga
I ended up with 1) installing from the link/official site (no brew) and then 2) brew install docker – and the issue has gone.Labrie
H
5

If you successfully installed docker using the official package, the command should be available under /usr/local/bin/docker.

That directory might not yet be in your $PATH, so you could try adding it, run:

export PATH="/usr/local/bin:$PATH"

this adds /usr/local/bin to the front of your PATH.

credit: https://mcmap.net/q/205394/-docker-commands-not-found


Detais:

Check docker is not there:

docker
zsh: command not found: docker

Check what PATH is:

echo $PATH
/Users/brandomiranda/.opam/__coq-platform.2022.01.0~8.15~beta1/bin:/Users/brandomiranda/opt/anaconda3/envs/meta_learning/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin

Then add PATH (To set it for current shell and all processes started from current shell use export):

export PATH="/usr/local/bin:$PATH"

Check what I added to Path:

echo $PATH
/usr/local/bin:/Users/brandomiranda/.opam/__coq-platform.2022.01.0~8.15~beta1/bin:/Users/brandomiranda/opt/anaconda3/envs/meta_learning/bin:/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin

Seems that /usr/local/bin wasn't in my path. Probably odd? Seems odd to me...why isn't it there?

Huggermugger answered 14/4, 2022 at 19:34 Comment(2)
Nope. I installed and ran Docker desktop, and there is no /usr/local/bin at all. In fact, sudo find /usr -name docker finds nothing!Orndorff
As of November 2023, docker installed from the official site docs.docker.com/desktop/install/mac-install is NOT under /usr/local/bin/docker !! I can't find where my docker command isZymogen
B
5

I started getting this error when my Docker Desktop (in macOS Sonoma) was updated to 4.25.0 version.

Turns out, I have to add $HOME/.docker/bin to the PATH on versions 4.18 and later, because Docker CLI tools are installed in the user directory now as shown in the settings below:

Steps:

  1. Check the shell you're using.

    echo $0
    

    For eg: I'm using bash.

  2. I'm using bash, so I ran this command

    vim ~/.bash_profile
    

    But if you're using zsh, you'd run this instead

    vim ~/.zshrc
    
  3. Add this to the file

    export PATH=$PATH:~/.docker/bin
    
  4. Hit Esc, type :wq and hit enter to save and quit.

  5. In order to pick up the changes to your profile, either close and reopen the terminal, or manually source your respective ~/.profile. For my case, I ran this command

    source ~/.bash_profile
    

It starts working at this point:

Reference: https://docs.docker.com/desktop/settings/mac/#advanced-1

Bennink answered 6/11, 2023 at 1:17 Comment(0)
E
5

MacOS Sonoma 14.3.1 , Docker 4.28.0

Inside Docker desktop, go to Settings > Advanced Settings

You'll see Choose how to configure the installation of Docker's CLI tools

I changed it from User to System. It resolved the issue for me.

Eggleston answered 26/3, 2024 at 22:54 Comment(0)
S
3

============================================================================

If you are using a Rancher desktop on MAC (mac OS Ventura) and facing this issue

============================================================================

  1. vi ~/.zshrc

  2. Add below line at the very end

export PATH="$HOME/.rd/bin:$PATH"
  1. Save and exit

  2. On the terminal execute the following command

source ~/.bashrc 
  1. check if docker command is available now
docker ps
Sheepskin answered 3/6, 2023 at 0:43 Comment(0)
Y
1

I am using a MacOS Big Sur running on the Intel chip.

I installed the Docker desktop by installing the .dmg file from here: https://docs.docker.com/desktop/install/mac-install/

I am using .zsh (with the Warp terminal) and I kept getting this error: "zsh: command not found: docker" when I was typing in any command like "docker --version"

So I ran the following command in my zsh terminal:

echo PATH="$PATH:$HOME/.docker/bin" >> ~/.zshrc

I then restarted my terminal and now it works.

Ysabel answered 30/6, 2023 at 12:39 Comment(0)
L
1

execute following command in a cli

brew link docker
Langan answered 26/12, 2023 at 15:20 Comment(0)
B
1

There are many places from where the value of $PATH variable is influenced. Following is a way to add the path to it permanently in zsh:

  1. Open the terminal
  2. cd /etc/paths.d
  3. Create a new file with any name. For instance you want to create a path for docker then sudo vi dockerpath
  4. Paste your path in this file /Applications/Docker.app/Contents/Resources/bin
  5. Write and close. Press esc and :wq
  6. Open a new terminal to check if the newly added path is present. echo $PATH
Bullion answered 13/3, 2024 at 23:13 Comment(0)
C
0

You can also install docker with following command on Mac:

brew install docker-machine docker
Cattle answered 21/4, 2022 at 6:28 Comment(2)
re-installing using a different method may lead to conflicting versions. It´s better to solve the previous installation. Or if you suggest this new installation as a solution, then you should provide the cleaning-up steps before installation IMOHoey
agreed with the comment above. This sort of approach only messes up things even moreTigerish
U
0

So to install images, instead of

/bin/docker run -d -p 80:80 docker/getting-started

use

/Applications/Docker.app/Contents/Resources/bin/docker run -d -p 80:80 docker/getting-started
Underhanded answered 21/10, 2022 at 21:42 Comment(0)
M
0

If you used Homebrew to install Docker, you should open it in Applications, confirm the precautions, and add it to the background applications.

Then the Docker app is started, and you can use any commands of docker XXX.

Mutant answered 26/2, 2023 at 9:37 Comment(0)
T
0

Commands to fix the issue:

rm -rf ~/Library/Containers/com.docker.*
cd /usr/local/bin
chmod 0755 dock*

Then

  • quit Docker Desktop;
  • reopen Docker Desktop, probably wait for a minute for changes to be reflected.

Taken from the following YouTube video.

Towpath answered 31/7, 2023 at 11:37 Comment(1)
Not sure why this got a downvote. This was the only way I was able to solve the problem. One additional note: I had to go into Privacy & Security and give terminal full disk access to successfully delete all the Docker metadata in ~/Library/Containers/com.docker.*Subdivision
T
0

https://github.com/docker/for-mac/issues/6793#issuecomment-1546529682

  • this worked for me without doing path changes manually simply in advanced docker setting change to System -> save. If System is already checked then check User -> Save and then change back to System.
Tactic answered 8/4, 2024 at 7:5 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.