How can I enable accessing Docker through terminal in Mac without always typing ‘sudo’?
If I type docker or docker-compose, I'm getting 'ZSH command not found, but when I’m adding sudo it works as intended.
I tried to do the tricks found through the internet, but no one actually works: sudo dscl . delete /Groups/docker GroupMembership Myusername sudo chmod a+x /usr/local/bin/docker-compose
All types of other advices are intended for Linux, not Mac.
Strangely, when I watched many videos of using Docker commands in Terminal, all users which streamed their videos didn’t used sudo or wasn’t typing this commands under the root user.
Since the error message is “command not found” and not “permission denied”, I think there is nothing wrong with permissions and group membership. My guess is that /usr/local/bin is not in PATH variable in the ZSH shell. It could be for example because you tried to add a new fodler to PATH and acidentally overwrote it instead of appending or prepending a new value.
You can try the following ways to confirm it:
The below command should show you if the necessary folder is added to the PATH.
echo $PATH | tr ':' '\n' | grep '/usr/local/bin'
Start a bash shell from zsh and try docker from there:
bash -l
If /usr/local/bin is indeed missing from ZSH, you need to add it back or find out what and why removed it. Check your $HOME/.zshrc file for example.
So, as I take, the necessary folder is in the PATH and all is okay.
Start a bash shell from zsh and try docker from there:
bash -l
Here is an output. Switching zsh to bash hasn’t helped unfortunately. I made sure below that a switch of zsh → bash was done.
Deemone@Deemone ~ % echo $0
-zsh
Deemone@Deemone ~ % bash -l
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Deemone:~ Deemone$ echo $0
bash
Deemone:~ Deemone$ docker info
bash: docker: command not found
Deemone:~ Deemone$
Thank you for reporting.
I did reinstalling for several times after preceeding uninstall procedure, with no success.
I installed it straight like you showed it, by dragging and dropping to my applications folder and answered ‘yes’ when its asked for permissions.
That is strange. I didn’t expect that. Please try this command too:
which docker
and also this to show the permissions of docker related binaries
ls -la /usr/local/bin/docker*
and the same in the Docker app folder:
ls -la /Applications/Docker.app/Contents/Resources/bin/
Note: While I was typing my message @alishah730 asked for whosing the permissions too, but I will keep it in my message too
The strange thing is that if it is a permission issue, the message should be different and I tried to change thebroke the permissions and got different message.
In your first post you showed docker and docker-compose binary linked to binaries (I missed it first) in the Docker App so you shouldn’t have got an empty result after running
ls -la /usr/local/bin/docker*
What if you try this?
ls -la /usr/local/bin | grep docker
(I just don’t want to you to list all the files in that folder, because there could be commands that you don’t wan to share)
I still don’t understand what is happening but if something happened during the installation of Docker Desktop, you could try to completely remove every component which I ams ure you tried, but I know from experience it is not always easy to find all the remained compontents. I have made a video about it, although it was for an odler version but I mention in the video too that I shared only ideas not a perfect solution for every case. You can still try it: Uninstalling Docker Desktop properly on macOS - YouTube
Deemone@Deemone ~ % ls -la /usr/local/bin
total 0
ls: /usr/local/bin: Permission denied
Under SU its all works. So, as I take, there is something wring with my system.
I runned a clear copy of MacOS in Virtual machine it it successfully does ls -la /usr/local/bin without su.
Yes, I tried to remove Docker completely with searching for its files + system files included + searching in stackoverflow for where it can leave its traces. I will investigate into your video, thanks.
Now that is a problem. It looks like you don’t have permission to see files in the folder so the fact that you could execute files inside doesn’t help.
Please, try this now:
ls -ld /usr/local/bin
It should show this:
drwxr-xr-x 30 root wheel 960 Mar 13 01:06 /usr/local/bin
The fodler has to be “executable” by anyone otherwise you can’t list files inside. If it is the case, then giving back the permision to the fodler could solve the issue (let’s hope it does)