Updating npm in Docker image

问题内容:

I am building a Node.js Docker image: docker build . -t imagename, however I keep getting warning regarding npm version

npm WARN deprecated This version of npm lacks support for important features,
npm WARN deprecated such as scoped packages, offered by the primary npm
npm WARN deprecated registry. Consider upgrading to at least npm@2, if not the
npm WARN deprecated latest stable version. To upgrade to npm@2, run:
npm WARN deprecated 
npm WARN deprecated   npm -g install npm@latest-2
npm WARN deprecated 
npm WARN deprecated To upgrade to the latest stable version, run:
npm WARN deprecated 
npm WARN deprecated   npm -g install npm@latest
npm WARN deprecated 
npm WARN deprecated (Depending on how Node.js was installed on your system, you
npm WARN deprecated may need to prefix the preceding commands with `sudo`, or if
npm WARN deprecated on Windows, run them from an Administrator prompt.)
npm WARN deprecated 
npm WARN deprecated If you're running the version of npm bundled with
npm WARN deprecated Node.js 0.10 LTS, be aware that the next version of 0.10 LTS
npm WARN deprecated will be bundled with a version of npm@2, which has some small
npm WARN deprecated backwards-incompatible changes made to `npm run-script` and
npm WARN deprecated semver behavior.

However I have update Node.js version, and it still wouldn’t work:

node -v
v8.9.3
npm -v
5.6.0

I have ran npm -g install npm@latest but still won’t work.

Dockerfile

FROM alpine:3.1

# Update
RUN apk add --update nodejs

# Install app dependencies
COPY package.json /src/package.json
RUN cd /src; npm -g install npm@latest

# Bundle app source
COPY . /src

CMD ["node", "--harmony","/src/app.js"]

What could possibly be the cause? I am able to run the app using node just fine.

I’m running Ubuntu 16.04.3 LTS

问题评论:

    
Can you post the contents of the Dockerfile please
    
Question updated with Dockerfile
– Khaled
1 hour ago
1  
Is there a reason you are not using the official node image? hub.docker.com/_/node
    
Also worth checking that you arent specifying an old Node version in your package.json
1  
Recommend either updating alpine to latest (3.7) or using the nodejs docker image (FROM in the Dockerfile)

答案:

答案1:

In Dockerfile, I used latest alpine version FROM alpine:3.7 instead and it works.

答案评论:

原文地址:

https://stackoverflow.com/questions/47755140/updating-npm-in-docker-image

添加评论

友情链接:蝴蝶教程