Skip to content

Instantly share code, notes, and snippets.

@jesugmz
Last active October 23, 2021 21:25
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesugmz/bc6a751e36486f4c8e44461fa4e06764 to your computer and use it in GitHub Desktop.
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
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
@roynasser
Copy link

Came across this on google, hasnt worken for mme on php7.2 or 7.3 using debian stretch-slim... Have you used this recently?

@jesugmz
Copy link
Author

jesugmz commented Jun 15, 2019

Came across this on google, hasnt worken for mme on php7.2 or 7.3 using debian stretch-slim... Have you used this recently?

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment