Software & AppsOperating SystemLinux

How To Fix “bash: docker: command not found” Error on Ubuntu Server via SSH

Ubuntu 6

In this article, we will be discussing a common error that many users encounter when trying to run Docker commands on an Ubuntu server via SSH: “bash: docker: command not found”. We will provide detailed instructions on how to resolve this issue and get your Docker commands running smoothly.

Quick Answer

To fix the "bash: docker: command not found" error on Ubuntu Server via SSH, you can either use the full path to the Docker executable when running Docker commands, create a symlink to the Docker executable in a directory included in the PATH, or update the PATH environment variable to include the directory where the Docker executable is located.

Understanding the Error

Before we delve into the solutions, it’s important to understand what this error message means. The “bash: docker: command not found” error is typically encountered when the system cannot find the Docker executable in the directories listed in the PATH environment variable. This could be due to Docker being installed in a directory that is not included in the PATH, or Docker not being installed at all.

Prerequisites

Before proceeding with the solutions, ensure that Docker is installed on your Ubuntu server. If it’s not, you can follow the official Docker installation guide to install Docker.

Solution 1: Use the Full Path to the Docker Executable

The simplest solution to this error is to specify the full path to the Docker executable when running Docker commands. For example, instead of running docker info, you would run /snap/bin/docker info.

Here is what the command does:

  • ssh user@host: This command logs you into the server as the specified user.
  • '/snap/bin/docker info': This command runs the docker info command on the server. The /snap/bin/docker part specifies the full path to the Docker executable.

Solution 2: Create a Symlink to the Docker Executable

If you don’t want to specify the full path every time you run a Docker command, you can create a symlink (symbolic link) to the Docker executable in a directory that is included in the PATH.

Here’s how to do it:

$ sudo ln -s /snap/bin/docker /usr/bin/docker

In this command:

  • sudo: This command runs the following command with root privileges.
  • ln -s /snap/bin/docker /usr/bin/docker: This command creates a symlink to the Docker executable.

Solution 3: Update the PATH Environment Variable

Another solution is to update the PATH environment variable to include the directory where the Docker executable is located. You can do this by editing the ~/.ssh/environment file on the server and adding the following line:

PATH=/snap/bin:$PATH

Note: You need to have the PermitUserEnvironment option set to yes in the sshd_config file for this to work.

Conclusion

By following one of these solutions, you should be able to resolve the “bash: docker: command not found” error and use the docker command without specifying the full path. Remember to always check your PATH and ensure Docker is installed properly to avoid such errors in the future.

What should I do if Docker is not installed on my Ubuntu server?

If Docker is not installed on your Ubuntu server, you can follow the official Docker installation guide to install Docker.

How can I check if Docker is installed on my Ubuntu server?

You can check if Docker is installed on your Ubuntu server by running the command docker --version. If Docker is installed, it will display the version number. If it’s not installed, you will see an error message.

How do I log into my Ubuntu server via SSH?

To log into your Ubuntu server via SSH, you can use the ssh command followed by the username and IP address of the server. For example: ssh username@server_ip. You will be prompted to enter the password for the specified user.

How do I edit the `~/.ssh/environment` file on the server?

To edit the ~/.ssh/environment file on the server, you can use a text editor such as nano or vi. For example, you can run the command nano ~/.ssh/environment to open the file in the nano editor. Make your changes, save the file, and exit the editor.

How can I check the value of the `PATH` environment variable?

You can check the value of the PATH environment variable by running the command echo $PATH. It will display the directories included in the PATH variable, separated by colons.

Leave a Comment

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