How to upgrade npm to npm@5 on the latest node docker image?

Viewed 5917

Locally, I have successfully installed npm@5 via:

$ npm install npm@5 -g
$ npm -v
$ 5.0.0

And locally, I can run the npm setup just fine (it's basically npm i && tsc)

$ npm run setup 
updated 102 packages in 3.499s

Yet now I also have a Dockerfile based upon the node:7.10-alpine image which breaks if I try to install npm@5 there.

My Dockerfile looks like this:

FROM node:7.10-alpine
WORKDIR /usr/hive-updater/
ENV LAST_UPDATED=2016-12-08 NPM_CONFIG_LOGLEVEL=warn TERM=xterm PATH="$PATH:/usr/hive-updater/node_modules/.bin"
RUN npm install npm@5 -g && npm -v
COPY ./ ./
RUN npm run setup
CMD ["node"]

This will fail during npm -v with:

module.js:472
    throw err;
    ^

Error: Cannot find module 'semver'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/unsupported.js:2:14)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)

How to get the latest npm on my docker container?

1 Answers
Related