How to create a Docker image for PHP and Node?

前端 未结 2 1689
梦毁少年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:02

    I suggest you do it differently. Since php is longer than install, use the php image and install node.

    FROM php:5.6-apache
    
    RUN apt-get update && apt-get install -y node npm
    #WORKDIR is /var/www/html
    COPY . /var/www/html/
    RUN npm install
    

    And then you have apache2 provides .php files.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题