0

I am trying to create a centos image with latest node.js LTS version and a npm package. Everything works until the npm command which then fails with the following error:

 > [5/5] RUN npm install -g express-generator-typescript:
#8 1.928 /bin/sh: npm: command not found

Here is my Dockerfile:

FROM centos

RUN touch $HOME/.bashrc && \
    yum -y install tar gzip gunzip

RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash \
    && . $HOME/.bashrc \
    && nvm install --lts

RUN npm install -g express-generator-typescript

Note:

  1. I want nvm to dynamically install the latest LTS version of node.js.
  2. If I typed the same commands in a centos container, I can install the NPM package.

How do I solve this problem?

Web User
  • 7,438
  • 14
  • 64
  • 92
  • 1
    Most Docker paths don't read shell dotfiles like `.bashrc`. Correspondingly, version managers like `nvm` that depend on shell dotfile tricks won't work well. Don't use `nvm`; just install the single specific version of Node you need. – David Maze Mar 21 '21 at 11:03
  • (The [Docker Hub `node` image](https://hub.docker.com/_/node) has an `lts` tag, so one easy approach is to skip the manual setup and just build your image `FROM node:lts`.) – David Maze Mar 21 '21 at 11:04
  • Sourcing the .bashrc file worked, allowing node.js to get installed with `nvm install --lts`. But it looks like node and npm are not in PATH. I tried specifying PATH and NODE_PATH but that didn't help either. – Web User Mar 21 '21 at 15:11

0 Answers0