The npm command is not found in my NodeJS docker container
<p>I created a Docker image:</p>

<pre><code>$ docker build -t stephaneeybert/nodejs .
Sending build context to Docker daemon  2.56 kB
Step 1 : FROM debian
 ---&gt; 1b088884749b
Step 2 : RUN apt-get clean &amp;&amp; apt-get update
 ---&gt; Using cache
 ---&gt; b12133d6342f
Step 3 : RUN apt-get install -y curl
 ---&gt; Using cache
 ---&gt; 22dfb4882b12
Step 4 : RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash
 ---&gt; Using cache
 ---&gt; 27f2fac45254
Step 5 : RUN . ~/.nvm/nvm.sh; nvm install stable
 ---&gt; Using cache
 ---&gt; 20d99d545755
Step 6 : RUN . ~/.nvm/nvm.sh; nvm use stable
 ---&gt; Using cache
 ---&gt; 9ec14efb2407
Step 7 : RUN . ~/.nvm/nvm.sh; npm install -g npm
 ---&gt; Using cache
 ---&gt; d264d38565f3
Step 8 : EXPOSE 9001
 ---&gt; Using cache
 ---&gt; 29e3589557e1
Step 9 : ENTRYPOINT /usr/bin/tail -f /dev/null
 ---&gt; Using cache
 ---&gt; 2ce499300fe1
Successfully built 2ce499300fe1
</code></pre>

<p>The image script is:</p>

<pre><code>FROM debian

RUN apt-get clean &amp;&amp; apt-get update
RUN apt-get install -y curl

# Installing nodesjs

RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash

RUN . ~/.nvm/nvm.sh; nvm install stable
RUN . ~/.nvm/nvm.sh; nvm use stable
RUN . ~/.nvm/nvm.sh; npm install -g npm

EXPOSE 9001

ENTRYPOINT ["/usr/bin/tail", "-f", "/dev/null"]
</code></pre>

<p>Then I run the container and open a bash shell:</p>

<pre><code>$ docker run -d -p 127.0.0.1:9001:9001 --name nodejs stephaneeybert/nodejs
c6dddf0a5eb0f11c897f63910eb01f2868fe0f39a80e5e2a580ef3a82935b27b
[stephane@stephane-ThinkPad-X301 nodejs]
$ docker exec -it nodejs bash
root@c6dddf0a5eb0:/# 
</code></pre>

<p>Once in there, I try to get the version:</p>

<pre><code>root@c6dddf0a5eb0:/# npm -v
bash: npm: command not found
</code></pre>

<p>But npm is not found.</p>

<p>When typing the command <code>nvm use stable</code> in the interactive shell, it give the following error: <code>N/A: version "N/A" is not yet installed.</code></p>

<p>I understand there is an alias against a non existant node version.</p>

<p>The <code>nvm ls</code> command shows:</p>

<pre><code>root@60446f9286d0:/# nvm ls
            N/A
node -&gt; stable (-&gt; N/A) (default)
iojs -&gt; N/A (default)
</code></pre>

<p>The debugger has this to show:</p>

<pre><code>root@60446f9286d0:/# nvm debug
nvm --version: v0.32.1
$SHELL: /bin/bash
$HOME: /root
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: none
which node: 
which iojs: 
which npm: 
npm config get prefix: bash: npm: command not found
npm root -g: bash: npm: command not found
</code></pre>

<p>1- How come I need to source this script <code>. ~/.nvm/nvm.sh;</code> on each command?</p>

<p>2- Why is my Node package manager not found in the bash shell?</p>

<p>EDIT: I changed a bit the content of the Dockerfile file:</p>

<pre><code>RUN curl -o-https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash \
  &amp;&amp; . ~/.nvm/nvm.sh \
  &amp;&amp; nvm install stable \
  &amp;&amp; nvm alias default stable \
  &amp;&amp; nvm use default
</code></pre>

<p>And building it now shows this:</p>

<pre><code>Step 4 :RUN curl -o https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash   &amp;&amp; . ~/.nvm/nvm.sh   &amp;&amp; nvm install stable   &amp;&amp; nvm alias default stable   &amp;&amp; nvm use default
 ---&gt; Running in 7d2c404135dd
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10250  100 10250    0     0  18258      0 --:--:-- --:--:-- --:--:-- 18238
=&gt; Downloading nvm as script to '/root/.nvm'

=&gt; Appending source string to /root/.bashrc
=&gt; Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="/root/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] &amp;&amp; . "$NVM_DIR/nvm.sh"  # This loads nvm
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v7.2.0 (npm v3.10.9)
Creating default alias: default -&gt; stable (-&gt; v7.2.0 *)
default -&gt; stable (-&gt; v7.2.0 *)
Now using node v7.2.0 (npm v3.10.9)
 ---&gt; ad960a4addbe
Removing intermediate container 7d2c404135dd
Step 5 : EXPOSE 9001
 ---&gt; Running in df9284421302
 ---&gt; 14d386f009fb
Removing intermediate container df9284421302
Step 6 : ENTRYPOINT /usr/bin/tail -f /dev/null
 ---&gt; Running in fa2d71b6dfdf
 ---&gt; d02c8e88eb7f
Removing intermediate container fa2d71b6dfdf
Successfully built d02c8e88eb7f
</code></pre>

<p>I can see it installed node v7.2.0 and is using it.</p>

<p>But when I log into the container with the command <code>docker exec -it nodejs bash</code> it does not see any node anywhere:</p>

<pre><code>root@f8f2a32b462a:/# nvm --version   
0.32.1
root@f8f2a32b462a:/# npm --version   
bash: npm: command not found
root@f8f2a32b462a:/# echo $NVM_DIR   
/root/.nvm
root@f8f2a32b462a:/# ls -l /root/.nvm
total 100
-rwxr-xr-x 1 root root   313 Nov 26 13:01 nvm-exec
-rw-r--r-- 1 root root 95660 Nov 26 13:01 nvm.sh
root@f8f2a32b462a:/# ls -l /root/.npm
ls: cannot access /root/.npm: No such file or directory
</code></pre>