ZSH: command not found: docker

zsh: docker command not found

If you are trying to run the docker command in a shell and you get the error message "zsh: command not found: docker", it means that the docker command is not installed or not added to the system path. To fix this error, you must install Docker and add the docker command to your system path.

Understanding the "docker command not found" error

When you enter a command in the terminal, the shell searches for the corresponding binary executable file in the directories listed in the $PATH environment variable. If it cannot find the file, it will return a "command not found" error. This error can occur for various reasons, such as:

  • The binary executable file is not installed on the system

  • The binary executable file is not in the $PATH environment variable

  • The binary executable file is not executable or has the wrong permissions

  • The binary executable file is corrupted or damaged

Why Docker is not found in ZSH?

If you have installed Docker on your system but still encounter the "command not found: docker" error in ZSH, there are several reasons why this might happen. One common reason is that Docker is not in the $PATH environment variable. Another reason is that the Docker binary executable file may not be in the directory that the shell is searching for it.

Fixing the "command not found: docker" error in ZSH

There are several ways to fix the "command not found: docker" error in ZSH. Here are some of the most common methods:

Adding Docker to the $PATH environment variable

The first thing to check is whether Docker is in the $PATH environment variable. To do this, run the following command in the terminal:

echo $PATH

This command will display a list of directories that are searched for executable files. If the directory containing the Docker executable file is not in this list, you need to add it to the $PATH environment variable. You can do this by adding the following line to your shell configuration file (e.g., ~/.zshrc):

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

Installing Docker Compose

If you are using Docker Compose, you need to install it separately. Docker Compose is a tool that allows you to define and run multi-container Docker applications. To install Docker Compose, follow the instructions in the official documentation:

https://docs.docker.com/compose/install/

Restarting the ZSH shell

Sometimes, the changes you make to the $PATH environment variable or to the shell configuration file may not take effect immediately. In such cases, you need to restart the ZSH shell by running the following command:

exec zsh

Using an alias

Another way to fix the "command not found: docker" error is to create an alias for the Docker command. An alias is a custom shortcut that you can use to execute a command or a series of commands. To create an alias for Docker, add the following line to your shell configuration file:

alias docker='sudo /usr/bin/docker'

This command creates an alias for the Docker command and specifies the full path to the Docker executable file.

Using the full path to the Docker executable

If adding Docker to the $PATH environment variable or creating an alias does not work, you can try using the full path to the Docker executable file. The full path to the Docker executable file may vary depending on your operating system and the version of Docker you have installed. To find the full path, run the following command:

which docker

This command will display the full path to the Docker executable file. You can then use this path to execute Docker commands:

/usr/bin/docker ps

Checking the installation and version of Docker

If none of the above methods work, you should check whether Docker is installed correctly and whether you have the latest version. To check the installation and version of Docker, run the following command:

docker --version

This command will display the version of Docker that is installed on your system. If you do not have Docker installed, you can download it from the official Docker website:

https://www.docker.com/get-started

What is Docker?

Docker is a platform for building, running, and managing containerized applications. It allows developers to package their applications and dependencies into self-contained units called containers, which can be easily moved and deployed on any system that supports Docker.

Docker provides many benefits, including running applications in a lightweight, isolated environment and running applications on any system that supports Docker, regardless of the underlying operating system or infrastructure. This makes it easy to build, test, and deploy applications quickly and reliably and scale them up or down as needed.

You will need to install the Docker engine on your system to use Docker. This will provide the necessary tools and libraries for building, running, and managing Docker containers. You will also need to know how to use the Docker command line interface (CLI), which is used to interact with the Docker engine and manage containers.

Once you have installed Docker and learned how to use the Docker CLI, you can start building and running Docker containers for your applications. You can also use Docker to manage and deploy your applications in production, using tools and services provided by Docker or third-party vendors.

What is ZSH?

ZSH (Z Shell) is an advanced shell that is similar to the Bash shell but offers more features and customization options. It is commonly used by developers and power users who want more control over their shell environment. ZSH has several built-in features, including command-line completion, history search, and spelling correction. It also supports plugins and themes, which can be used to customize the shell's appearance and behavior.

Related articles

Ruslan Osipov
Written by author: Ruslan Osipov