Linux 127High

Error 'docker: command not found' in Linux: Causes and Solutions

This article explains why the 'docker: command not found' error occurs in Linux and provides step-by-step solutions, from installing Docker to configuring the PATH environment variable.

Updated at February 15, 2026
10-15 min
Easy
FixPedia Team
Применимо к:Ubuntu 20.04/22.04Debian 10/11CentOS 7/8Fedora 35/36Arch Linux

What the 'docker: command not found' Error Means

The docker: command not found error in Linux means that the shell (bash, zsh, etc.) cannot find the docker executable file in the directories specified in the PATH environment variable.

The full error text may look like:

bash: docker: command not found

or

zsh: command not found: docker

This error occurs when attempting to run any Docker command (docker --version, docker ps, etc.). Return code 127 (standard for "command not found") confirms that the system did not locate the docker executable in the search paths.

Causes

  1. Docker is not installed on the system at all.
  2. Docker is installed, but the path to the executable is not added to the PATH variable. This can happen with a manual installation from a binary archive or if the package manager did not configure PATH automatically.
  3. The terminal session has not been updated after Docker installation. Changes to PATH only take effect after restarting the session (or running source on the shell profile file).
  4. Attempting to run Docker via sudo with a cleared environment (by default, sudo may reset PATH). In this case, Docker might only be accessible by specifying the full path.
  5. Corrupted Docker installation or deletion of the executable file.

Solutions

Method 1: Install Docker

If Docker is not installed, perform an installation appropriate for your distribution.

For Ubuntu/Debian:

sudo apt update
sudo apt install docker.io

For CentOS/RHEL 7:

sudo yum install docker

For CentOS/RHEL 8 / Fedora:

sudo dnf install docker

For Arch Linux:

sudo pacman -S docker

After installation, verify that the docker file appears in standard locations (usually /usr/bin/docker).

Method 2: Add Docker's Path to the PATH Variable

If Docker is installed but the command does not work, you need to add the directory containing the executable to PATH.

  1. Locate the docker executable:
    sudo find / -name docker -type f 2>/dev/null | head -5
    

    The path is typically /usr/bin/docker or /usr/local/bin/docker.
  2. Add the path to PATH via the shell configuration file:
    • For bash (the default shell in Ubuntu/Debian/CentOS):
      echo 'export PATH=$PATH:/usr/bin' >> ~/.bashrc
      
      (replace /usr/bin with your directory if different)
    • For zsh:
      echo 'export PATH=$PATH:/usr/bin' >> ~/.zshrc
      
  3. Apply the changes:
    source ~/.bashrc   # or source ~/.zshrc
    

Method 3: Restart the Session

Sometimes simply restarting the terminal or logging out and back in is sufficient. This updates PATH to reflect any changes made by the package installer.

Method 4: Check Permissions and Configure sudo

Ensure your user has permission to execute the docker file:

ls -l $(which docker)

If execute permissions (x) are missing, fix them:

sudo chmod +x $(which docker)

To use Docker without sudo, add your user to the docker group:

sudo usermod -aG docker $USER

⚠️ Important: After adding to the docker group, you must log out and back in or restart your session for the changes to take effect.

Method 5: Verify the Installation

After completing the previous steps, check if Docker works:

docker --version

If the command returns a version, the issue is resolved. For a full check, run a test container:

docker run hello-world

On success, you will see Docker's welcome message.

Prevention

  • When installing via official repositories (apt, dnf, yum, pacman), Docker is usually added to PATH automatically. Restart your terminal after installation.
  • With manual installations (downloading a binary archive), always manually add the executable's directory to PATH.
  • Regularly update Docker through your package manager to avoid compatibility issues.
  • Use user groups (docker) to manage permissions instead of running via sudo every time.

Frequently Asked Questions

Q: What to do if which docker doesn't find the command, but Docker is clearly installed?
A: Check if the docker file exists in your system (sudo find / -name docker -type f). If the file exists but in a non-standard directory (e.g., /usr/local/bin/docker), add that directory to PATH as described in Method 2.

Q: Why doesn't the Docker command work after installing via apt until a reboot?
A: The docker.io package adds the path via the file /etc/profile.d/docker.sh, which is only loaded when a new session starts. Restart your terminal or run source /etc/profile.d/docker.sh.

Q: Can I use Docker in cron jobs?
A: Yes, but PATH is usually limited in cron jobs. Specify the full path to docker (e.g., /usr/bin/docker) or configure the PATH variable within the cron file itself.

Q: Why does sudo docker work, but docker does not?
A: This is a classic sign that docker is not in your user's PATH, but it is installed globally. When using sudo, a different configuration file may load where PATH includes system directories. Solution: add docker to PATH for your user (Method 2).

F.A.Q.

What to do if Docker is installed but the command doesn't work?
How to check if Docker is installed?
Why doesn't the Docker command work after installation?
Can Docker be used without adding to PATH?

Hints

Check if Docker is installed
Install Docker (if not present)
Add Docker path to PATH
Reload terminal session
Verify Docker functionality
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community