我想在一个单独的RUN中运行npm install。
这是dockerfile
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash \
&& export NVM_DIR="$HOME/.nvm" \
&& [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" \
&& nvm install node && nvm use node \
&& npm cache clean -f && npm install -g n && n stable && npm install cross-env \
&& npm install \
&& npm run dev
在这种情况下,npm install工作
但当我将其转换为:
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash \
&& export NVM_DIR="$HOME/.nvm" \
&& [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" \
&& nvm install node && nvm use node \
&& npm cache clean -f && npm install -g n && n stable && npm install cross-env
RUN npm install
RUN npm run dev
它说
/bin/sh: 1: npm: not found
为什么???
答案 0 :(得分:1)
为我工作:https://gist.github.com/remarkablemark/aacf14c29b3f01d6900d13137b21db3a
ENV NODE_VERSION 15.8.0
RUN apt update\
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash\
&& . $HOME/.nvm/nvm.sh\
&& nvm install $NODE_VERSION
ENV NODE_PATH /root/.nvm/v$NODE_VERSION/lib/node_modules
ENV PATH /root/.nvm/versions/node/v$NODE_VERSION/bin:$PATH