If you are using the Zsh shell on your Mac and have encountered the frustrating docker command not found error while trying to run Docker commands, don’t worry. Follow this article’s guidelines to fix the docker command not found error in Zsh.
How to Fix – docker command not found Error when Running in Zsh on Mac
The Mac users commonly faced the docker command not found error when they executed the docker-related commands in the Zsh terminal.
What are the Possible Causes of the Error and Fixes?
1: Docker is not Installed on macOS
One of the primary causes for this type of error in the system is the missing or misconfigured Docker installation. By default, Docker isn’t installed on macOS and if you have recently started using the macOS, you have to install Docker by opening the Zsh terminal and executing the following command:
When you run the above command, it will start installing docker on Zsh, which will take some time and once it is done, run the docker command again to fix the issue.
If Homebrew isn’t installed, you can run the following script file to install it successfully on macOS.
2: Updating PATH Configuration
Another factor that can generate the docker command not found error is the incorrect PATH configuration. The PATH is an environment variable containing a directories list where the system looks for executable files. If the location of the Docker executable file is not added to the PATH, the shell won’t be able to locate and run the docker command, causing an error message stating “command not found“. Therefore, it is better to update the PATH configuration using the following steps to fix the error.
Step 1: Open the Zsh terminal and run the command to open .zshrc configuration file.
Step 2: Add the path given below at the end of the .zshrc file.
Note: The docker path can be found using the following command:
Step 3: Once the changes are made to the .zshrc file, save it using CTRL+X, add Y, and enter to exit.
After that, you can run any docker command without any error.
Conclusion
Docker is a powerful tool that allows developers to automate the development process, however, when using the Zsh shell on a Mac, you may encounter the docker command not found error, which occurs because of missing or misconfigured Docker installation or an incorrect PATH configuration. By following the steps mentioned in this guide, such as installing Docker through Homebrew and updating the PATH configuration, you can resolve the error and successfully run Docker commands in Zsh on your Mac.