{"id":2625,"date":"2022-04-07T21:16:21","date_gmt":"2022-04-08T02:16:21","guid":{"rendered":"https:\/\/promincproductions.com\/blog\/?p=2625"},"modified":"2022-12-28T09:31:49","modified_gmt":"2022-12-28T15:31:49","slug":"access-docker-command-via-ssh-on-qnap-ts-251","status":"publish","type":"post","link":"https:\/\/promincproductions.com\/blog\/access-docker-command-via-ssh-on-qnap-ts-251\/","title":{"rendered":"Access Docker Command via SSH on QNAP TS-251"},"content":{"rendered":"<p>QNAP has built an application into it&#8217;s web interface called <strong>Container Station<\/strong> that is really a graphical interface for <strong>Docker<\/strong>.  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.<\/p>\n\n\n\n<p>The issue however is that when connecting to the QNAP TS-251 server via SSH, typing <code>docker<\/code> isn&#8217;t found.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bash: docker: command not found<\/code><\/pre>\n\n\n\n<p>This tutorial will allow the <code>docker<\/code> command to be found and run on a QNAP TS-251 via the SSH command line.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img decoding=\"async\" src=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/04\/docker-on-qnap-TS-251.png\" alt=\"Expose the docker command to SSH terminal command line on QNAP TS-251\" class=\"wp-image-2649\" width=\"-104\" height=\"-104\" title=\"Expose the docker command to SSH terminal command line on QNAP TS-251\" srcset=\"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/04\/docker-on-qnap-TS-251.png 600w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/04\/docker-on-qnap-TS-251-500x500.png 500w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/04\/docker-on-qnap-TS-251-150x150.png 150w, https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/04\/docker-on-qnap-TS-251-450x450.png 450w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><figcaption class=\"wp-element-caption\">Expose the docker command to SSH terminal command line on QNAP TS-251<\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">What is Docker<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.docker.com\/\" target=\"_blank\" rel=\"noopener\" data-lasso-id=\"768\">Docker<\/a> allows for building virtual machines.  It is a software platform that has gained a lot of popularity since it&#8217;s inception in 2013.  In Docker, a <em>container<\/em> is created which holds all of the server details.  This includes an image of the operating system as well as <em>environment variables<\/em> 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why the <code>docker<\/code> Command Isn&#8217;t Found by Default on QNAP TS-251<\/h2>\n\n\n\n<p>QNAP devices run on a Linux based system.  Within Linux, executable commands can live in many directories.  When a command like <code>docker<\/code> is executed, Linux will search the known directories for executable commands for the related binary file.  If it&#8217;s found, then the program runs as expected.  If not, an error is raised and nothing happens.<\/p>\n\n\n\n<p>Linux  &#8211; the subsystem that the QNAP operating system is built on &#8211; stores the list of directories to search in the <code>PATH<\/code> <em>environment variable<\/em>.  Simply <em>echo<\/em> the variable to see the currently defined paths.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo $PATH\n\/bin:\/sbin:\/usr\/bin:\/usr\/sbin:\/usr\/bin\/X11:\/usr\/local\/bin<\/code><\/pre>\n\n\n\n<p>This list of paths is colon (<code>:<\/code>) 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.<\/p>\n\n\n\n<p>The <code>docker<\/code> command however does not live within any of those directories and thus attempting to run the <code>docker<\/code> command raises an error.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker\nbash: docker: command not found<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Finding the Docker Path in the Filesystem<\/h2>\n\n\n\n<p>Knowing where the <code>docker<\/code> command lives in the filesystem is the next step.  Once that is identified, it can be added to the <code>PATH<\/code> variable and then the <code>docker<\/code> command will run as expected.  To find the path where <code>docker<\/code> lives, run this find command.   This will search the entire file system to look for the <code>docker<\/code> executable.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/ -type f -name 'docker-init' -perm +111 -print\n\/share\/CACHEDEV1_DATA\/.qpkg\/container-station\/usr\/bin\/.libs\/docker-init\n\/share\/CACHEDEV1_DATA\/.qpkg\/container-station\/bin\/docker-init<\/code><\/pre>\n\n\n\n<p>Some tribal knowledge indicates that the later of the two results found is the desired path.  The <code>docker-init<\/code> file name needs to be removed from the path as on the paths should be added to the <code>PATH<\/code> environment variable &#8211; not the files themselves.  Now that the path has been identified, the <code>PATH<\/code> variable can be updated.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Add the Docker Path to the PATH Environment Variable<\/h2>\n\n\n\n<p>To add the Docker path to the <code>PATH<\/code> environment variable the <code>export<\/code> command will be used.  <code>export<\/code> is a builtin function of the shell to access the systems environment variables.  (Fun note: running <code>export -p<\/code> will list all of the set environment variables)  <code>export<\/code> will be used to set the <code>PATH<\/code> 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 (<code>:<\/code>).<\/p>\n\n\n\n<p>Start with the <code>export<\/code> command followed by the environment variable to be set &#8211; <code>PATH<\/code> &#8211; followed by an equal sign (<code>=<\/code>) and the data to set to it.  In this case, use the current value of the <code>$PATH<\/code> variable and append the path to the <code>docker-init<\/code> executable<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export PATH=$PATH\":\/share\/CACHEDEV1_DATA\/.qpkg\/container-station\/bin\/:\"<\/code><\/pre>\n\n\n\n<p>Confirm that the <code>PATH<\/code> variable was updated correctly with <code>echo<\/code> again.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo $PATH\n\/bin:\/sbin:\/usr\/bin:\/usr\/sbin:\/usr\/bin\/X11:\/usr\/local\/bin:\/share\/CACHEDEV1_DATA\/.qpkg\/container-station\/bin\/:<\/code><\/pre>\n\n\n\n<p>Now that the <code>export<\/code> command has been run, the <code>docker<\/code> command now functions!  To test that, run <code>docker -v<\/code> to check the version of Docker.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker -v\nDocker version 20.10.11-qnap1, build 90a753c<\/code><\/pre>\n\n\n\n<p>This command works for this one shell instance.  Once the terminal window (PuTTY) is closed, the <code>PATH<\/code> variable is set back to it&#8217;s default in the next terminal window that is opened.  Simply run the command again the next time a terminal window is opened.<\/p>","protected":false},"excerpt":{"rendered":"<p>QNAP has built an application into it&#8217;s web interface called Container Station that is really a graphical interface [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2649,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wprm-recipe-roundup-name":"","wprm-recipe-roundup-description":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[387,384,332],"tags":[335,354,330,333],"class_list":["post-2625","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-home-assistant","category-qnap","category-smart-home","tag-container-station","tag-docker","tag-qnap","tag-ts-251"],"jetpack_featured_media_url":"https:\/\/promincproductions.com\/blog\/wp-content\/uploads\/2022\/04\/docker-on-qnap-TS-251.png","jetpack_shortlink":"https:\/\/wp.me\/p4BbcR-Gl","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/2625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/comments?post=2625"}],"version-history":[{"count":6,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/2625\/revisions"}],"predecessor-version":[{"id":3077,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/posts\/2625\/revisions\/3077"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/media\/2649"}],"wp:attachment":[{"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/media?parent=2625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/categories?post=2625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/promincproductions.com\/blog\/wp-json\/wp\/v2\/tags?post=2625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}