[Fixed] bash: docker command not found

In Linux, Docker is a free and open-source tool for developers that enables them to develop, run, update, and manage containers. It combines the source code of the application with the required dependencies and libraries in the operating system which is required for the application. When using the Docker’s command in Linux, the user can face the error “bash: command not found”.

This article will demonstrate the reasons and solutions for the “bash: command not found” error. The content for this post is as follows:

Let’s get into the first reason.

Reason 1: Docker Not Installed

The reason for this error is that Docker is not installed in your operating system. The solution for this is to install Docker first in your operating system, which is given below.

Solution: Installing Docker

To install docker, first install the required dependencies using the below-given command:

$ sudo apt install ca-certificates software-properties-common apt-transport-https gnupg-agent curl

For CentOS/RHEL:

$ sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Once the dependencies have been installed, add the GPG (GNU Privacy Guard) key:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Now, add the repository for installing the docker. To do this, the following command will be used:

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

For CentOS/RHEL:

$ yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

After adding the repository, run the update command in the terminal to update the package:

$ sudo apt update

All packages are up-to-date.

Finally, install the Docker using the below command in the terminal:

$ sudo apt install docker-ce docker-ce-cli containerd.io

Docker has been installed in the opening system.

For CentOS/RHEL:

$ sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

To verify the Docker installation, check the version of the Docker:

$ docker -v

The above image shows the Docker version is 20.10.21.21.

Reason 2: Docker Command Located On Different Path

Another possible reason for this error could be the location of the Docker. Maybe your Docker is located in another directory apart from “/bin/docker”, so in that case, you can create the symbolic link to that directory.

Solution: Creating Symbolic Link

To create the symbolic link, first search the path of your Docker. You can use the “whereis” or “locate” commands for searching. Once you found the path, paste it in the following command and run it in the terminal:

$ ln -s /[Path to the Docker] /bin/docker

The above command will create the symbolic link, and you can access the directory of the Docker.

Reason 3: Installed Only the GUI Version of Docker

There could be another possible reason for this error is that most of the users directly install Docker using the “sudo apt install docker-ce docker-ce-cli containerd.io” command. This command only installs the graphical user interface for Docker, not the dev tool, which ultimately causes the users to be met with the error in question.

Solution: Properly Install Docker

The solution for this is to install Docker properly, which is already given in Reason 1’s solution. So uninstall the Docker GUI tool you have installed and follow the above guide for installing docker.

For uninstalling Docker, use the following command:

$ sudo apt autoremove docker

These are the solutions for the given error.

Conclusion

The reasons for this error are that Docker is not installed, it is located in another directory, or the user has only installed the GUI version of Docker. To fix this error, the user can install Docker using the given guide, create the symbolic link if Docker is located in another directory, or properly install the Docker. All the reasons and solutions for the error “bash: docker command not found” has illustrated in this write-up.