-
-
Save TitasGailius/1f6ce9045938299ab53f608236839eac to your computer and use it in GitHub Desktop.
Muli-Stage Docker image for Laravel applications
This file contains 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
# | |
# PHP Dependencies | |
# | |
FROM composer:2.0 as vendor | |
WORKDIR /app | |
COPY database/ database/ | |
COPY composer.json composer.json | |
COPY composer.lock composer.lock | |
RUN composer install \ | |
--no-interaction \ | |
--no-plugins \ | |
--no-scripts \ | |
--no-dev \ | |
--prefer-dist | |
COPY . . | |
RUN composer dump-autoload | |
# | |
# Frontend | |
# | |
FROM node:14.9 as frontend | |
WORKDIR /app | |
COPY artisan package.json webpack.mix.js yarn.lock tailwind.js ./ | |
RUN yarn install | |
COPY resources/js ./resources/js | |
COPY resources/sass ./resources/sass | |
RUN yarn production | |
# | |
# Application | |
# | |
FROM php:7.4-fpm | |
WORKDIR /app | |
# Install PHP dependencies | |
RUN apt-get update -y && apt-get install -y libxml2-dev | |
RUN docker-php-ext-install pdo pdo_mysql mbstring opcache tokenizer xml ctype json bcmath pcntl | |
# Copy Frontend build | |
COPY --from=frontend /app/node_modules/ ./node_modules/ | |
COPY --from=frontend /app/public/js/ ./public/js/ | |
COPY --from=frontend /app/public/css/ ./public/css/ | |
COPY --from=frontend /app/public/mix-manifest.json ./public/mix-manifest.json | |
# Copy Composer dependencies | |
COPY --from=vendor /app/vendor/ ./vendor/ | |
COPY . . | |
RUN php artisan config:cache | |
RUN php artisan route:cache |
I get No package 'oniguruma' found
when I want to build this. I added RUN apt-get install -y libonig-dev
to fix this issue.
FWIW, You might not need to explicitly install mbstring
(or oniguruma
) in the Dockerfile, if you're starting with the PHP image. See the official image, it looks like mbstring
is already installed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't need to copy the node_modules in the last step. After
yarn production
all necessary javascript is compiled into the javascript files inpublic/js
.