How to create a Docker image for PHP and Node?

前端 未结 2 1691
梦毁少年i
梦毁少年i 2021-01-15 08:53

I am trying to create a Cocker container for my Angular that has a PHP file in it. Angular requires npm so I need to have Node.js installed. I don\'t need Apache for my proj

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-15 09:17

    I think in this case the better way is using node docker image and PHP docker image together like bellow and not installing one of them by using apt-get install

    FROM node:latest AS node
    FROM php:7.4-fpm
    
    COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
    COPY --from=node /usr/local/bin/node /usr/local/bin/node
    RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
    
    RUN mkdir -p /usr/src/app
    WORKDIR /usr/src/app
    
    COPY package.json /usr/src/app
    RUN npm install
    
    COPY . /usr/src/app
    

    in this way you don't need to install either node or PHP package every time that you change your code and rebuild from scratch is required in your Dockerfile

提交回复
热议问题