How to install nvm in docker?

后端 未结 14 965
陌清茗
陌清茗 2020-12-04 05:53

I am in the process of building a new Docker image and I\'m looking to get NVM installed so I can manage nodejs.

Reading the docs on how to install NVM they mention

14条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 06:55

    Each RUN in a Dockerfile is executed in a different container. So if you source a file in a container, its content will not be available in the next one.

    That is why when you install an application and you need to do several steps, you must do it in the same container.

    With your example:

    ADD files/nvm_install.sh /root/
    RUN chmod a+x /root/nvm_install.sh && \
      /root/nvm_install.sh && \
      source /root/.bashrc && \
      cd /root && \
      nvm install 0.10.31
    

提交回复
热议问题