Last active
October 23, 2021 21:25
-
-
Save jesugmz/bc6a751e36486f4c8e44461fa4e06764 to your computer and use it in GitHub Desktop.
Example how to build Docker multi-stage image using official PHP and Composer images
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
ARG PHP_VERSION=7.2-fpm-stretch | |
ARG COMPOSER_VERSION=latest | |
# builder stage | |
FROM php:$PHP_VERSION AS builder | |
ARG AMQP_VERSION=1.9.3 | |
ARG PHPREDIS_VERSION=4.1.1 | |
RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests \ | |
librabbitmq-dev \ | |
libxml2-dev \ | |
libzip-dev \ | |
procps \ | |
unzip \ | |
zip \ | |
&& docker-php-ext-install -j$(nproc) \ | |
soap \ | |
pdo_mysql \ | |
zip \ | |
&& pecl install \ | |
amqp-$AMQP_VERSION \ | |
redis-$PHPREDIS_VERSION \ | |
&& docker-php-ext-enable \ | |
amqp \ | |
redis \ | |
&& rm -rf /tmp/* /var/lib/apt/lists/* | |
COPY ./docker/php/config/base.ini /usr/local/etc/php/conf.d/10-base.ini | |
WORKDIR /appdata | |
# development stage | |
FROM composer:$COMPOSER_VERSION AS composer | |
FROM builder AS dev | |
ARG XDEBUG_VERSION=2.6.1 | |
RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests \ | |
git \ | |
vim \ | |
&& pecl install \ | |
xdebug-$XDEBUG_VERSION \ | |
&& docker-php-ext-enable \ | |
xdebug \ | |
&& rm -rf /tmp/* /var/lib/apt/lists/* | |
COPY --from=composer /usr/bin/composer /usr/bin/composer | |
COPY ./docker/php/config/dev.ini /usr/local/etc/php/conf.d/50-dev.ini | |
RUN composer global require hirak/prestissimo | |
# testing stage | |
FROM builder AS test | |
RUN apt-get update && apt-get install -y --no-install-recommends --no-install-suggests \ | |
git \ | |
&& rm -rf /var/lib/apt/lists/* | |
COPY --from=composer /usr/bin/composer /usr/bin/composer | |
RUN composer global require hirak/prestissimo | |
# production stage | |
FROM builder AS prod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @roynasser didn't this before sorry. That example is coping libraries folders directly from one contaniner to others and is risky, can break dependencies. A better example can be the new one where is only copying binaries, not libraries (the Dockerfile has been updated).