Install node in Dockerfile?

前端 未结 4 1777
天涯浪人
天涯浪人 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:31

    Get the node image and put it at the top of your dockerfile:

    FROM node:[tag_name] AS [alias_name]
    

    Verify the version by adding following code:

    RUN echo "NODE Version:" && node --version
    RUN echo "NPM Version:" && npm --version
    

    Then add the following code every time you need to use nodejs in a container:

    COPY --from=[alias_name] . .
    


    From the codes above, replace the following with:

    [tag_name] - the tag value of the node image you want to use. Visit https://hub.docker.com/_/node?tab=tags for the list of available tags.

    [alias_name] - your preferred image name to use in your dockerfile.


    Example:

    FROM node:latest AS node_base
    
    RUN echo "NODE Version:" && node --version
    RUN echo "NPM Version:" && npm --version
    
    
    FROM php:5.6-apache
    
    COPY --from=node_base . .
    
    ### OTHER CODE GOES HERE
    

提交回复
热议问题