Access Docker Command via SSH on QNAP TS-251

QNAP has built an application into it’s web interface called Container Station that is really a graphical interface for Docker. This is a great tool, however has limited functionality and depending on what tasks need to be done, having access to Docker via the command line is necessary.

The issue however is that when connecting to the QNAP TS-251 server via SSH, typing docker isn’t found.

This tutorial will allow the docker command to be found and run on a QNAP TS-251 via the SSH command line.

Expose the docker command to SSH terminal command line on QNAP TS-251
Expose the docker command to SSH terminal command line on QNAP TS-251

What is Docker

Docker allows for building virtual machines. It is a software platform that has gained a lot of popularity since it’s inception in 2013. In Docker, a container is created which holds all of the server details. This includes an image of the operating system as well as environment variables that control default settings and configuration. Storage can also be configured so that the virtual machine can be shut down and upon reboot any data that was saved previously will persist. Hardware devices and network connections are also configured and shared from the host device to the Docker container.

Why the docker Command Isn’t Found by Default on QNAP TS-251

QNAP devices run on a Linux based system. Within Linux, executable commands can live in many directories. When a command like docker is executed, Linux will search the known directories for executable commands for the related binary file. If it’s found, then the program runs as expected. If not, an error is raised and nothing happens.

Linux – the subsystem that the QNAP operating system is built on – stores the list of directories to search in the PATH environment variable. Simply echo the variable to see the currently defined paths.

This list of paths is colon (:) separated. In the output above, there are 6 paths that Linux searches. Linux will search these paths in order until it finds the executable command.

The docker command however does not live within any of those directories and thus attempting to run the docker command raises an error.

Finding the Docker Path in the Filesystem

Knowing where the docker command lives in the filesystem is the next step. Once that is identified, it can be added to the PATH variable and then the docker command will run as expected. To find the path where docker lives, run this find command. This will search the entire file system to look for the docker executable.

Some tribal knowledge indicates that the later of the two results found is the desired path. The docker-init file name needs to be removed from the path as on the paths should be added to the PATH environment variable – not the files themselves. Now that the path has been identified, the PATH variable can be updated.

Add the Docker Path to the PATH Environment Variable

To add the Docker path to the PATH environment variable the export command will be used. export is a builtin function of the shell to access the systems environment variables. (Fun note: running export -p will list all of the set environment variables) export will be used to set the PATH environment variable with the Docker path. The Docker path needs to be appended to the current list that was found above, with a trailing colon (:).

Start with the export command followed by the environment variable to be set – PATH – followed by an equal sign (=) and the data to set to it. In this case, use the current value of the $PATH variable and append the path to the docker-init executable

Confirm that the PATH variable was updated correctly with echo again.

Now that the export command has been run, the docker command now functions! To test that, run docker -v to check the version of Docker.

This command works for this one shell instance. Once the terminal window (PuTTY) is closed, the PATH variable is set back to it’s default in the next terminal window that is opened. Simply run the command again the next time a terminal window is opened.