FROM debian:latest replace shell with bash so we can source files RUN rm /bin/sh && ln…
- User
FROM debian:latest
replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
update the repository sources list
and install dependencies
RUN apt-get update
&& apt-get install -y curl
&& apt-get -y autocleannvm environment variables
ENV NVM_DIR /usr/local/nvm ENV NODE_VERSION_14 14.21.3 ENV NODE_VERSION_16 16.20.2 RUN mkdir -p $NVM_DIR
RUN apt-get update && apt-get install -y build-essential libssl-dev python3 gnupg2
install nvm
https://github.com/creationix/nvm#install-script
RUN curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
RUN /bin/bash -c “source $NVM_DIR/nvm.sh”
install node and npm LTS
RUN source NVM_DIR/nvm.sh \ && nvm install NODE_VERSION_14
&& nvm alias default NODE_VERSION_14 \ && nvm use default \ && nvm install NODE_VERSION_16 \add node and npm to path so the commands are available
ENV NODE_PATH NODE_VERSION_14/lib/node_modules ENV PATH NODE_VERSION_14/bin:$PATH
- Assistant
你的 Dockerfile 报错消息
/root/entrypoint.sh: line 3: nvm: command not found是因为在执行 ENTRYPOINT 时,nvm还没有被正确地加载。nvm是通过source命令加载的,但是这个命令只在具体的 shell 中有效,并不会跨进程或者跨脚本生效。另外,
nvm安装脚本会将nvm的初始化脚本加入到用户的 shell 配置文件中,比如.bashrc或者.bash_profile。所以默认情况下,您需要确保在启动新的 shell 时也执行这些初始脚本,这才能确保nvm命令可用。您可以尝试以下方法更新 Dockerfile 来解决这个问题:
dockerfile