首页 > 解决方案 > Npm install 特定版本在 Dockerfile 中不起作用

问题描述

我正在尝试在图像(最新标签)中安装特定版本的 npm 包node:alpine,所以这是我在 Dockerfile 中指定的:

编辑(这是完整的 Dockerfile):

FROM node:alpine as build-stage
ARG SONAR_VERSION=4.6.0.2311
RUN apk add --no-cache zip unzip
RUN wget -c https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_VERSION-linux.zip

RUN unzip -q sonar-scanner-cli-$SONAR_VERSION-linux.zip
RUN rm sonar-scanner-cli-$SONAR_VERSION-linux.zip

# Adding the $install_directory/bin directory to path
RUN cd sonar-scanner-$SONAR_VERSION-linux
RUN echo $PWD
RUN export PATH="$PATH:/$PWD/bin"

RUN npm i -g eslint@6.7.2
RUN npm i -g eslint-plugin-vue --save-dev

但是,当我运行并执行构建的映像时,安装的 eslint 版本是最新版本,而不是我在 Dockerfile 中指定的版本。

结果来自npm list -g

/ # npm list -g
/usr/local/lib
+-- eslint-plugin-vue@7.9.0
+-- eslint@7.25.0
`-- npm@7.11.2

如果我npm i -g eslint@6.7.2在容器本身中运行,则版本npm list -g将完全是我指定的版本。

这种情况的原因是什么?

标签: dockernpmdockerfileeslint

解决方案


推荐阅读