runnerpaul
runnerpaul

Reputation: 7256

Docker command not found when running on Mac

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?

Upvotes: 149

Views: 333784

Answers (28)

kratnu
kratnu

Reputation: 27

The most voted answer by Nepomucen helped me but after each Mac restart I have to do it all over again. So, I modified Zsh configuration file

nano ~/.zshrc insert export PATH="$PATH:/Applications/Docker.app/Contents/Resources/bin/" save & restart terminal (probably there is an option to reload newly added path, was easier to just restart). Voila, docker command is recognized after each start up

Upvotes: 0

Ash K
Ash K

Reputation: 3731

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 (Press i to enter INSERT mode)

    export PATH="$PATH:$HOME/.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

Upvotes: 10

udance4ever
udance4ever

Reputation: 101

I had a Docker Desktop for macOS install that was not behaving correctly because I was using it on two different users.

I uninstalled Docker on one user which rightfully cleaned up and removed the links in /usr/local/bin

However, when I went to reinstall Docker on the other user, it must have found its configuration files so it never bothered to run the installation wizard and restore the links in /use/local/bin

What I didn't realize is I had a notification in Docker Desktop that the links were missing and there was a "Repair" button and it recreated the symlinks (and some other tasks)

It is no longer necessary to update your PATH (though I admit, this solution is nice and worked initially but won't work if scripts use an absolute path like /usr/local/bin/docker to perhaps prevent malicious versions of docker from showing up).

Upvotes: 1

Nepomucen
Nepomucen

Reputation: 6707

I'm afraid you need to add the 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 Docker Desktop for Mac (docker)
export PATH="$PATH:/Applications/Docker.app/Contents/Resources/bin/"

Upvotes: 337

  • Open Docker Desktop and click on the gear icon to access Settings.
  • Go to the Advanced tab.
  • Under "Choose how to configure the installation of Docker's CLI tools:", select "User".
  • Click "Apply & Restart".
  • After Docker restarts, go back to Settings -> Advanced.
  • Now, select "System" under "Choose how to configure the installation of Docker's CLI tools:".
  • Click "Apply & Restart" again.

Upvotes: 2

Johnny Cage
Johnny Cage

Reputation: 6400

You need to install docker

brew install docker

Upvotes: -2

Shreyansh Jain
Shreyansh Jain

Reputation: 422

Edit: After updating the docker version, I get the error again.

Added export PATH="$PATH:/Applications/Docker.app/Contents/Resources/bin/" to .zshrc and got resolved.

Original:

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.

Upvotes: 14

Karthik P
Karthik P

Reputation: 29

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

By adding the above line in ".zshrc" file.

Able to run the docker command.

Upvotes: 1

Ankit Bamanpalli
Ankit Bamanpalli

Reputation: 34

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.

Upvotes: 1

Varun
Varun

Reputation: 21

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

Upvotes: 1

cane
cane

Reputation: 1027

execute following command in a cli

brew link docker

Upvotes: 2

Vineet Kumar Gupta
Vineet Kumar Gupta

Reputation: 535

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/"

Upvotes: 19

Mary
Mary

Reputation: 11

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.

Upvotes: 0

seem7teen
seem7teen

Reputation: 273

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

Upvotes: 6

salborough
salborough

Reputation: 29

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.

Upvotes: 1

Amit Meena
Amit Meena

Reputation: 4454

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

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

Upvotes: 4

Lycheek1ng
Lycheek1ng

Reputation: 241

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

Upvotes: 22

C RICH
C RICH

Reputation: 513

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!

Upvotes: 8

Tom Harrison
Tom Harrison

Reputation: 14078

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.

Upvotes: 9

Blue Stragglers
Blue Stragglers

Reputation: 11

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.

Upvotes: 1

o-az
o-az

Reputation: 633

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.

Upvotes: 44

Tatiana
Tatiana

Reputation: 1

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

Upvotes: 0

Joy
Joy

Reputation: 4511

You can also install docker with following command on Mac:

brew install docker-machine docker

Upvotes: 0

Mark
Mark

Reputation: 111

This command helped me:

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

Check version after that:

docker --version

Upvotes: 11

Charlie Parker
Charlie Parker

Reputation: 5267

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://stackoverflow.com/a/57231241/1601580


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?

Upvotes: 5

Michael Vilain
Michael Vilain

Reputation: 69

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.

Upvotes: 6

Priyanka
Priyanka

Reputation: 425

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/

Upvotes: 39

dataplumber
dataplumber

Reputation: 417

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/

Upvotes: 13

Related Questions