Docker

How to Add Docker to Your Mac’s System Path?

Docker is a tool that allows you to create, run, and manage containers and has a command-line tool called docker cli to interact with the docker daemons (a program that runs docker containers). Some users may experience a docker command not found error even after installing the docker on their systems. The primary reason for this error could be the fact that your system fails to find docker executable file. To fix the issue, you have to add docker to your system path variable.

Read this article for a complete guide on how to add docker to your Mac’s system path.

What is a System Path Variable?

The system path variable is a directories list that your system searches for executable files. It is used during the file execution at the terminal. Whenever you try to execute a command in the terminal, the system will look in the directories in the system path and will run the file if it is there with that name.

Why is System Path Variable Useful?

The system path is useful since it allows you to run executable files from anywhere on your system. For example, if you have an executable file in your home directory, you can run it by typing its name into the terminal, even if the file is not in the current directory.

How to Add Docker to Your Mac’s System Path?

To add docker to your system path variable on Mac, use the following steps:

Step 1: First check the path to the docker binary on your system using the following command

which docker

Where the docker binary is the executable file that is used to run docker commands on Mac. The above command ensures that docker cli tools are installed inside the /usr/local/bin directory on Mac.

Step 2: You need to add this path inside your Bash or Zsh configuration file. However, before that check whether you are using Bash or Zsh on your Mac and for that you have to run the following command:

echo $0

Since in my case, I am using Zsh, so I have to go with the .zshrc configuration file. If you are using Bash, you can go with .bashrc.

Step 3: Now, open the .bashrc or .zshrc configuration file on your Mac using the nano editor:

nano ~/.zshrc

Step 4: Add the path you just noted in Step 1 at the bottom of the .zshrc or .bashrc configuration file.

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

Step 5: Save the above configuration file using Ctrl+Y+Enter and then use the following command to reload the changes to .zshrc or .bashrc configuration file.

source ~/.zshrc

Note: Don’t forget to replace .zshrc with .bashrc if you are using a Bash configuration file.

If the source command runs without an error, it confirms that you have successfully added docker to your Mac’s system path.

Conclusion

You can add docker to the system path on Mac by first running the which docker command on the terminal to look for the docker path. Then you have to open the .zshrc or .bashrc configuration file and add the docker path at the bottom of the file. After that, you have to reload changes to the file using the source command to complete the process of adding system path for docker on 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.