docker command not found

Docker is one of the most used virtualization technologies nowadays. Have you ever heard someone talking about it? It could happen at a conference, in a work meeting, if you know someone in the IT sector, etc.

Docker is used by a lot of people in a lot of different projects, and if you don’t know it yet then you are about to. If you came across this article searching for a solution for the docker: command not found error then you have come to the right place, so please keep reading.

Since a lot of people use Docker then a lot of people have crossed paths with the error that we mentioned before, which is the typical “command not found” error that you get when you are trying to run a certain binary in your Terminal application. Not even Docker is safe from this error, so now let’s see why this error happens and how can we fix the “docker command not found” error on the terminal.

Contents

bash: docker command not found

So, why are you getting this error? Well, the main reason is actually very simple: Docker is currently not installed on your system or not available in the proper path. Yes, those are pretty simple reasons but are the most commons ones and a lot of people lose too much time looking for the root of their problem when it usually comes to the mentioned situations.

The famous "docker command not found" error on the terminal

The “docker command not found” error on the terminal means that the docker binary couldn’t be found in the expected route, this can happen for different reasons:

  • docker is not installed on your system, or if you tried to install it then it may have been installed incomplete.
  • The docker binary is not available in the expected path. Sometimes, depending on how you install your software, creating a custom binary is necessary to run that particular software. If this is happening in your case then you will get the same error even if Docker was installed.
  • There is also another situation in which the “command not found” error can appear for Docker, it’s very common in some Ubuntu systems so we are going to explain this one below after the fix for the other cases.

How can I fix this error?

Ok, we have seen some different situations in which we can get the docker: command not found error, so now let’s see how can we fix this and get the docker command running properly.

The most common situation is that Docker is not installed or wasn’t properly installed. To make sure you install docker the right way you can run the following commands as the root user of your system.

Install Docker on CentOS/RHEL

First, we have to install some dependencies:

yum install yum-utils device-mapper-persistent-data lvm2

Now we add the Docker repo:

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

And finally, we install Docker:

yum install docker-ce

And that’s it, Docker is now installed on your CentOS/RHEL system and you shouldn’t get the not found error anymore.

Install Docker on Ubuntu/Debian

First, we have to update the apt index:

apt-get update

Now we install some necessary packages:

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

It’s time to add the official GPG key:

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

Now let’s configure apt to use the stable version of the Docker repo:

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

And finally, install Docker:

apt-get update
apt-get install docker-ce docker-ce-cli containerd.io

That’s it for Ubuntu/Debian, you should have the docker command installed now and the not found error is gone for good.

Another reason for getting the docker: command not found error is that the docker command is on a different path. This can happen sometimes depending on how you installed docker. The fix is actually pretty simple, you just have to create a symbolic link to the correct command.

First, you have to find the location of the docker command that was installed, if you know the location then perfect, but if you don’t you will have to use tools like the command “find” to, well, find it.

Once the docker binary has been found you just have to create the symbolic link:

ln -s /pathto/thedockerbinary/thatyoufound /bin/docker

In this example, you have to replace “/pathto/thedockerbinary/thatyoufound” with the real path of the docker binary that you found.

Why do I get docker command not found even if it’s installed?

This is a very common problem in some Ubuntu systems, for example, Ubuntu 16.04. Some people install docker right away just running this:

apt get install docker

This will install Docker of course, but not the Docker that you want. If you install it this way, then what you are installing is actually the GUI tool Docker, not the dev tool that you are looking for. As a result, you will get the command not found error when you try to run docker in the terminal.

The solution? Make sure that you install Docker the proper way, in this same article we have already provided you with a quick tutorial to install Docker on Ubuntu/Debian systems, so uninstall that GUI tool that you installed before and make sure you follow the right steps to install Docker.

Summary

Today we have learned a bit more about Docker and one of the most commons errors we can come across while using it, which is docker command not found. As we have seen in this article, this problem happens because Docker wasn’t installed properly or because it was installed in a custom path.

The solution in both cases is pretty simple: install Docker using the provided tutorials for CentOS/RHEL and Ubuntu/Debian (you can also check the tutorials on Docker’s Documentation website), or create a symlink in case the binary was installed in a custom location in your system.

Finally, if the problem is happening on Ubuntu and you are 100% sure that you installed it the right way then check again, because you may have actually installed the Docker GUI tool. This software is different from the Docker that you really need, which is the dev tool that you run from your terminal.

References:

About the Author: Martin Keler

Leave a Reply

Your email address will not be published. Required fields are marked *