How to install nvm in docker?

后端 未结 14 952
陌清茗
陌清茗 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:35

    A key difference between the attempt to get the nvm command in the question:

    RUN bash -l -c "source /root/.bashrc"
    

    which doesn't work and the attempt to do the same in the accepted answer:

    source $NVM_DIR/nvm.sh
    

    Is that the second version sources the nvm.sh script directly, whereas the original tries to do it via the .bashrc file.

    The .bashrc file has a line in it early on which exits if it's being run in a non interactive shell:

    # If not running interactively, don't do anything
    case $- in
        *i*) ;;
        *) return;;
    esac
    

    So it never gets to the bit where it would have sourced nvm.sh which actually puts the nvm command in your shell.

    I wouldn't be surprised if docker is running this stuff in a non interactive shell. This hadn't been explicitly pointed out, so I thought I would mention it as it's what caught me out when I was doing something similar with vagrant.

提交回复
热议问题