-
-
Save anjilinux/0c5b2eeaa677616ec4475d582b24ebad to your computer and use it in GitHub Desktop.
project Dockerfile multi-stage example for JS/PHP App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ############################################################################### | |
| # Step 1 : NPM Builder image | |
| # | |
| FROM node:lts-alpine AS npm-builder | |
| # Define working directory and copy source | |
| WORKDIR /home/node/app | |
| COPY ./my_app/package.json ./my_app/modernizr-config.json ./ | |
| # Install dependencies and build whatever you have to build | |
| RUN apk add --no-cache git | |
| RUN echo "104.16.20.35 registry.npmjs.org" >> /etc/hosts | |
| RUN echo "192.30.253.112 github.com" >> /etc/hosts | |
| RUN npm install | |
| RUN npm run modernizr | |
| COPY ./my_app/ . | |
| RUN npm run production | |
| ############################################################################### | |
| # Step 2 : Composer Install | |
| # | |
| FROM composer:latest AS composer-install | |
| WORKDIR /home/node/app | |
| COPY ./my_app/database /home/node/app/database | |
| # Install deps for production only | |
| COPY ./my_app/composer.lock ./my_app/composer.json ./ | |
| RUN composer install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader | |
| ################################################################################### | |
| # Step 3 : Build Final Image | |
| FROM php:7-apache | |
| RUN apt-get update && apt-get install --no-install-recommends -y \ | |
| mysql-client \ | |
| libpng-dev \ | |
| libzip-dev \ | |
| libicu-dev \ | |
| && pecl install redis \ | |
| && docker-php-ext-enable redis \ | |
| && docker-php-ext-configure zip --with-libzip \ | |
| && docker-php-ext-install pdo_mysql pcntl tokenizer intl \ | |
| && docker-php-ext-install zip \ | |
| && a2enmod rewrite \ | |
| && apt-get purge \ | |
| && rm -rf /var/lib/apt/lists/* | |
| WORKDIR /var/www | |
| COPY ./my_app/ . | |
| # Copy builded source from the upper builder stage | |
| COPY --from=npm-builder /home/node/app/public ./public | |
| COPY --from=composer-install /home/node/app/vendor ./vendor | |
| ENV APACHE_DOCUMENT_ROOT /var/www/public | |
| RUN sed -ri -e 's!/var/www/html!/var/www/public!g' /etc/apache2/sites-available/*.conf | |
| RUN sed -ri -e 's!/var/www/!/var/www/public!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf | |
| RUN chown -R www-data:www-data /var/www/storage /var/www/bootstrap/cache /var/www/public | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment