zsh

How to Fix – docker command not found Error when Running in Zsh on Mac

Docker is an open-source platform used for automating the development and running of applications inside containers, where containers are lightweight and isolated environments that include all the required dependencies and configurations to run an application.

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:

brew install docker

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.

docker --version

If Homebrew isn’t installed, you can run the following script file to install it successfully on macOS.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

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.

sudo nano /etc/zshrc

Step 2: Add the path given below at the end of the .zshrc file.

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

Note: The docker path can be found using the following command:

which docker

Step 3: Once the changes are made to the .zshrc file, save it using CTRL+X, add Y, and enter to exit.

source /etc/zshrc

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.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.