From 42af959fa1df5fea48f9e1be57e1319e23d11f54 Mon Sep 17 00:00:00 2001 From: sochi Date: Tue, 2 Jun 2020 13:01:37 +0200 Subject: [PATCH] Add better example for usage with Composer --- README.md | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c317e28..aa8bd05 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ Repository: https://github.com/TrafeX/docker-php-nginx * Built on the lightweight and secure Alpine Linux distribution * Very small Docker image size (+/-35MB) -* Uses PHP 7.3 for better performance, lower cpu usage & memory footprint +* Uses PHP 7.3 for better performance, lower CPU usage & memory footprint * Optimized for 100 concurrent users -* Optimized to only use resources when there's traffic (by using PHP-FPM's ondemand PM) +* Optimized to only use resources when there's traffic (by using PHP-FPM's on-demand PM) * The servers Nginx, PHP-FPM and supervisord run under a non-privileged user (nobody) to make it more secure * The logs of all the services are redirected to the output of the Docker container (visible with `docker logs -f `) * Follows the KISS principle (Keep It Simple, Stupid) to make it easy to understand and adjust the image to your needs @@ -62,7 +62,7 @@ _Note; Because `-v` requires an absolute path I've added `pwd` in the example to ## Adding composer -If you need composer in your project, here's an easy way to add it; +If you need [Composer](https://getcomposer.org/) in your project, here's an easy way to add it. ```dockerfile FROM trafex/alpine-nginx-php7:latest @@ -73,3 +73,26 @@ COPY --from=composer /usr/bin/composer /usr/bin/composer # Run composer install to install the dependencies RUN composer install --optimize-autoloader --no-interaction --no-progress ``` + +### Building with composer + +If you are building an image with source code in it and dependencies managed by composer then the definition can be improved. +The dependencies should be retrieved by the composer but the composer itself (`/usr/bin/composer`) is not necessary to be included in the image. + +```Dockerfile +FROM composer AS composer + +# copying the source directory and install the dependencies with composer +COPY / /app + +# run composer install to install the dependencies +RUN composer install \ + --optimize-autoloader \ + --no-interaction \ + --no-progress + +# continue stage build with the desired image and copy the source including the +# dependencies downloaded by composer +FROM trafex/alpine-nginx-php7 +COPY --chown=nginx --from=composer /app /var/www/html +``` \ No newline at end of file