Reputation: 7256
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
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
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:
Check the shell you're using.
echo $0
For eg: I'm using bash
.
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
Add this to the file (Press i to enter INSERT mode)
export PATH="$PATH:$HOME/.docker/bin"
Hit Esc, type :wq
and hit enter to save and quit.
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
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
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
Reputation: 70
Upvotes: 2
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
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
Reputation: 34
https://github.com/docker/for-mac/issues/6793#issuecomment-1546529682
Upvotes: 1
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:
cd /etc/paths.d
sudo vi dockerpath
/Applications/Docker.app/Contents/Resources/bin
:wq
echo $PATH
Upvotes: 1
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
Reputation: 11
Commands to fix the issue:
rm -rf ~/Library/Containers/com.docker.*
cd /usr/local/bin
chmod 0755 dock*
Then
Taken from the following YouTube video.
Upvotes: 0
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
/usr/local/bin
)docker --version
Upvotes: 6
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
Reputation: 4454
============================================================================
If you are using a Rancher desktop on MAC (mac OS Ventura) and facing this issue
============================================================================
vi ~/.zshrc
Add below line at the very end
export PATH="$HOME/.rd/bin:$PATH"
Save and exit
On the terminal execute the following command
source ~/.bashrc
docker ps
Upvotes: 4
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
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
Reputation: 14078
As of docker desktop mac (in my case v4.18, Apple Silicon version), the default installation is
/usr/local/bin
$HOME/.docker/bin
See Docker Desktop > Settings > Advanced, which provides two options:
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
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
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
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
Reputation: 4511
You can also install docker
with following command on Mac:
brew install docker-machine docker
Upvotes: 0
Reputation: 111
This command helped me:
/Applications/Docker.app/Contents/Resources/bin/docker --version
Check version after that:
docker --version
Upvotes: 11
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
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
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
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