Install node in Dockerfile?

前端 未结 4 1769
天涯浪人
天涯浪人 2021-02-04 00:15

I am user of AWS elastic beanstalk, and I have a little problem. I want to build my CSS files with less+node. But I don`t know how to install node in my dockerfile, when buildin

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 00:28

    I am using following Dockerfile to setup node version 8.10.0.

    Here I have used NVM (Node Version Manager ), so we can choose which node version should be installed on that container. Please use absolute path of npm when installing node modules (eg: /root/.nvm/versions/node/v${NODE_VERSION}/bin/npm install leasot@latest -g)

       FROM ubuntu:18.04
       ENV NODE_VERSION=8.10.0
       RUN apt-get update && \
           apt-get install wget curl ca-certificates rsync -y
       RUN wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
       ENV NVM_DIR=/root/.nvm
       RUN . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION}
       RUN . "$NVM_DIR/nvm.sh" &&  nvm use v${NODE_VERSION}
       RUN . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION}
       RUN cp /root/.nvm/versions/node/v${NODE_VERSION}/bin/node /usr/bin/
       RUN cp /root/.nvm/versions/node/v${NODE_VERSION}/bin/npm /usr/bin/
       RUN /root/.nvm/versions/node/v${NODE_VERSION}/bin/npm install  leasot@latest -g
    

    Note: This is a cropped Dockerfile.

提交回复
热议问题