FUNDAMENTALS A Complete Guide for Beginners
When you run into the “bash: docker: command not found” error, it means that you are having trouble using Docker commands in the Bash shell. Usually, this problem occurs when Docker is not installed or cannot be found in the PATH of the system. Installing Docker and setting up the PATH is necessary to fix this issue and guarantee smooth integration.
Reasons for “docker” Command Not Found Error
Some common reasons for “docker” command not found error are:
- Docker not Installed: If you are unable to use the “docker” command, it could be that your system does not have Docker installed.
- Incorrect Installation Path: The PATH on your system may not contain Docker.
- Shell Session Not Refreshed: Restarting the shell session may be necessary if Docker was just installed for the modifications to take effect.
- Problems with Installation: The “docker” command may not exist because the Docker installation did not succeed.
- Inadequate permissions: Docker might not have the authorization it needs to function.
4 Methods to Solve “docker” Command Not Found in Bash
Follow the below methods to solve the docker command not found error in Bash:
1. Install Docker
Most of the time, an incorrect installation of Docker on your system causes the “bash: docker: command not found” error. In this instance, installing Docker fixes the issue. However, if your system has docker installed and still showing the error, first run sudo apt autoremove
docker. Now, follow the steps below to install Docker:
- Update apt-get repository using:
sudo apt-get update
- Install ca-certificates and curl using:
sudo apt-get install ca-certificates curl
- Now, run the commands below to create a directory for apt keyring, download the GPG key, and adjust permission:
sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc
- Then, add the Docker repository to the system’s package sources list using:
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update
- Finally, run the command below to install Docker:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- Now you can verify the Docker Engine installation using:
sudo docker run hello-world
Thus you can resolve the command not found error regarding docker.
2. Set “docker” PATH Variable
A prevalent reason behind the “docker command not found” is Docker is not present in your system PATH environment variables. To set the PATH variable for docker, follow the steps below:
- Press CTRL+ALT+T to open the terminal.
- Use which command to check the current path of Docker:
which docker
- Open bashrc file using:
nano ~/.bashrc
-
Now, replace <path to docker> in
export PATH=$PATH:<path to docker>
code with the which command’s output and paste it at the end of the file. For example:export PATH=$PATH:/usr/bin/docker
- Press CTRL+S to save, and CTRL+X to exit.
- Then, execute the bashrc file using:
source ~/.bashrc
- Now you can check running a docker command. For example:
docker –version
3. Start Docker Daemon
You will need to start the Docker daemon manually if it is not running even after installing and adding it to PATH. Your operating system will determine the precise steps, but in general, you can launch the Docker daemon by using the following command:
sudo service docker start
Run docker –version
to check if docker is activated now.
4. Create Symbolic Link to Docker
A symbolic link in Linux is a special type of file that serves as a reference or pointer to another file or directory. It acts as a shortcut, allowing users to create a link to a file or directory without copying its content. To create a symbolic link to docker, first get the path of docker using which or whereis command:
whereis docker
Now, execute ln -s /[path to the docker] /bin/docker
. Replace [path to the docker] with the directory found from whereis command. For example:
ln -s /usr/bin/docker /bin/docker
Conclusion
In conclusion, resolving the “bash docker command not found” issue involves ensuring the installation of Docker and configuring the system’s PATH appropriately. By applying these solutions, developers can seamlessly access Docker commands within the Bash environment and unlock Docker’s powerful containerization capabilities.
People Also Ask
Why my docker command is not found?
Possible reasons for the docker command not being found are: Docker not installed, PATH misconfiguration, terminal not restarted, insufficient permissions, or incorrect installation.
How to run bash in docker command?
Use docker run -it <image_name> bash
to run an interactive Bash shell within a Docker container. Replace <image_name> with the name or ID of the Docker image.
How do I enter Docker Bash?
To enter Docker Bash, use docker exec -it <container_name_or_id>
bash command. Replace <container_name_or_id> with the name or ID of the running Docker container.
How do I access a docker container Bash?
To access a Docker container’s Bash shell, use the command docker exec -it <container_name> bash
. Replace <container_name> with the name or ID of the running Docker container.
How to activate docker in cmd?
To activate Docker in Command Prompt (cmd), ensure Docker Desktop is installed and running. You can directly use CMD commands for Docker such as docker run
or docker ps
in the command prompt or script once Docker is set up. No separate activation is required.
How to solve “sudo: docker: command not found”?
If you’re getting the “sudo: docker: command not found” error, it means that the docker is not installed on your system, or it’s not in the system’s PATH for the user running the sudo command. To solve this error, install docker in your system. If docker is installed but you still get the error, open ./bashrc file and add the line below:
export PATH=$PATH:[path to docker]
To get the [path to docker], run which docker
command.
Related Articles
- [Fixed] “bash: sudo: command not found” Error
- [Solved] Bash “yarn” Command Not Found Error
- [Fixed] “bash: ng: command not found” Error
- [Fixed] “bash: java: command not found” Error
- Solved “bash: yum: command not found” [RHEL, Fedora, CentOS]
- [Solved] “bash: vim: command not found” Error
- [Fixed] “bash: curl: command not found” Error
- [Solved] “bash: node: command not found” Error
- [Solved] “bash: code: command not found” Error
- [Fixed!] “systemctl command not found” Error in Linux
<< Go Back to [Solved] “bash: command not found” Error | Bash Error Handling and Debugging | Bash Scripting Tutorial