title: Team City "minimal build agent" Docker image - "npm: not found" Linux issue?
body: <p>First of all, I <em>think</em> this is more of a Linux issue as the problem seems to be on a linux-flavoured Docker container, but I'm happy to accept that I can do something to the team city config to overcome this.</p>
  
  <p>I'm also not very experienced with Linux, Docker or node/npm, though I do have a lot of development experience and am very comfortable with command line interfaces in general.</p>
  
  <h2>Background</h2>
  
  <p>We currently have Team City set up as a build server, for building a variety of projects:</p>
  
  <ul>
  <li>.Net Framework, </li>
  <li>.Net Core</li>
  <li>Angular CLI </li>
  <li>A couple of simple websites which use node packages to generate HTML from Markdown.</li>
  </ul>
  
  <p>The server is running as a Docker container using Docker for Windows on a Windows Server box, and this is working well.<br>
  We have one Windows 10 Build agent (a VM) which is also working fine, and builds all the .Net and .Net Core stuff fine.</p>
  
  <p>The simple docs site stuff primarily uses the markdown-to-html node package, so its build steps simply get all the source .md files and compile to html with markdown-to-html, plus use some other npm packages for SASS compilation and minification of js etc.  No actual node code as such, just some jQuery.  In order to not tie up the other agent, and because this stuff can run happily on Linux, I want to have this running on a small docker image rather than a full VM build agent somewhere.</p>
  
  <p>I previously successfully used a node.js team city agent docker image (either <code>jacobpeddk/teamcity-agent-nodejs</code> or <code>omez/teamcity-agent-nodejs</code> - can't recall) which did work for a time, though I had issues with being able to install some npm packages globally in build scripts, which meant I had to get a bash terminal into the container and run some manual npm commands. I also I think had to run <code>apt-get install zip</code> to get a zipping step to work. This worked fine for a while (weeks).</p>
  
  <p>I added some extra JS stuff to one of these simple projects, and suddenly I was getting errors when trying to build.  I (perhaps stupidly) decided that this was probably due to the container having older versions of node and/or npm etc, so I attempted to update this by getting a bash shell into the container, installing nvm and updating node.js &amp; npm.</p>
  
  <p>This ended up with a rather broken container (node errors), so I thought I'd instead start again, but actually start with the <code>jetbrains/minimal-build-agent</code> Docker image instead, with the aim of ending up with a nice bespoke image for our needs specifically (as I couldn't find a very up-to-date pre-existing one)</p>
  
  <p>I've running a Bash shell directly on the build agent container by executing this on the host:</p>
  
  <pre><code>docker exec -it basicagent /bin/bash
  </code></pre>
  
  <p>then from there I've installed nvm, Python (required for node install step) and node:</p>
  
  <ul>
  <li><code>curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash</code></li>
  <li><code>export NVM_DIR="$HOME/.nvm"</code></li>
  <li><code>[ -s "$NVM_DIR/nvm.sh" ] &amp;&amp; \. "$NVM_DIR/nvm.sh"  # This loads nvm</code></li>
  <li><code>[ -s "$NVM_DIR/bash_completion" ] &amp;&amp; \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion</code></li>
  <li><code>apt-get update</code></li>
  <li><code>apt-get install python 3.6</code> </li>
  <li><code>nvm install v8.11.1</code> (matching version on my dev machine)</li>
  <li><code>npm install -g markdown-folder-to-html</code> (npm package I previously found I had to install globally)</li>
  <li><code>apt-get install zip</code> (just used for a build step to zip up artifacts)</li>
  </ul>
  
  <p>If I now run (via the bash shell) <code>npm -version</code> I get back 5.6.  </p>
  
  <p>If I try to get a build to run that uses npm in a command line step, then I get this error in the build log:
  <code>/opt/buildagent/temp/agentTmp/custom_script2764770419520852926: npm: not found</code></p>
  
  <p>I wondered if it was an issue with the user/path that the team city agent process is using vs. the one I'm using in Bash, so I added the following to the build script:</p>
  
  <pre><code>echo PATH = $PATH
  echo user var = $USER
  echo user via 'id':
  id -u -n
  </code></pre>
  
  <p>the output of which is:</p>
  
  <pre><code>PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  user var =
  user via id:
  root
  </code></pre>
  
  <p>So it's running the agent as <strong>root</strong>, and doesn't appear to have node in the $PATH at all.</p>
  
  <p>If I run the above directly from Bash however, I can see that I am root, but my $PATH is different:</p>
  
  <p><code>PATH = /root/.nvm/versions/node/v8.11.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin</code></p>
  
  <p><code>root</code></p>
  
  <p>So I'm now confused: I've re-started the container and this has had no effect - it seems that when I'm logged in as <strong>root</strong> manually I have a certain path set, but when the build agent service is running as <strong>root</strong> it's different.</p>