|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | + |
| 3 | +# Comments are provided throughout this file to help you get started. |
| 4 | +# If you need more help, visit the Dockerfile reference guide at |
| 5 | +# https://docs.docker.com/go/dockerfile-reference/ |
| 6 | + |
| 7 | +################################################################################ |
| 8 | + |
| 9 | +# Create a stage for installing app dependencies defined in Composer. |
| 10 | +FROM composer:lts as deps |
| 11 | + |
| 12 | +WORKDIR /app |
| 13 | + |
| 14 | +# If your composer.json file defines scripts that run during dependency installation and |
| 15 | +# reference your application source files, uncomment the line below to copy all the files |
| 16 | +# into this layer. |
| 17 | +# COPY . . |
| 18 | + |
| 19 | +# Download dependencies as a separate step to take advantage of Docker's caching. |
| 20 | +# Leverage a bind mounts to composer.json and composer.lock to avoid having to copy them |
| 21 | +# into this layer. |
| 22 | +# Leverage a cache mount to /tmp/cache so that subsequent builds don't have to re-download packages. |
| 23 | +RUN --mount=type=bind,source=composer.json,target=composer.json \ |
| 24 | + --mount=type=bind,source=composer.lock,target=composer.lock \ |
| 25 | + --mount=type=cache,target=/tmp/cache \ |
| 26 | + composer install --no-dev --no-interaction |
| 27 | + |
| 28 | +################################################################################ |
| 29 | + |
| 30 | +# Create a new stage for running the application that contains the minimal |
| 31 | +# runtime dependencies for the application. This often uses a different base |
| 32 | +# image from the install or build stage where the necessary files are copied |
| 33 | +# from the install stage. |
| 34 | +# |
| 35 | +# The example below uses the PHP Apache image as the foundation for running the app. |
| 36 | +# By specifying the "8.3-apache" tag, it will also use whatever happens to be the |
| 37 | +# most recent version of that tag when you build your Dockerfile. |
| 38 | +# If reproducability is important, consider using a specific digest SHA, like |
| 39 | +# php@sha256:99cede493dfd88720b610eb8077c8688d3cca50003d76d1d539b0efc8cca72b4. |
| 40 | +FROM php:8.3-apache as final |
| 41 | + |
| 42 | +RUN apt-get update && apt-get install -y libpq-dev && docker-php-ext-install pdo pdo_pgsql |
| 43 | + |
| 44 | +# Your PHP application may require additional PHP extensions to be installed |
| 45 | +# manually. For detailed instructions for installing extensions can be found, see |
| 46 | +# https://github.com/docker-library/docs/tree/master/php#how-to-install-more-php-extensions |
| 47 | +# The following code blocks provide examples that you can edit and use. |
| 48 | +# |
| 49 | +# Add core PHP extensions, see |
| 50 | +# https://github.com/docker-library/docs/tree/master/php#php-core-extensions |
| 51 | +# This example adds the apt packages for the 'gd' extension's dependencies and then |
| 52 | +# installs the 'gd' extension. For additional tips on running apt-get, see |
| 53 | +# https://docs.docker.com/go/dockerfile-aptget-best-practices/ |
| 54 | +# RUN apt-get update && apt-get install -y \ |
| 55 | +# libfreetype-dev \ |
| 56 | +# libjpeg62-turbo-dev \ |
| 57 | +# libpng-dev \ |
| 58 | +# && rm -rf /var/lib/apt/lists/* \ |
| 59 | +# && docker-php-ext-configure gd --with-freetype --with-jpeg \ |
| 60 | +# && docker-php-ext-install -j$(nproc) gd |
| 61 | +# |
| 62 | +# Add PECL extensions, see |
| 63 | +# https://github.com/docker-library/docs/tree/master/php#pecl-extensions |
| 64 | +# This example adds the 'redis' and 'xdebug' extensions. |
| 65 | +# RUN pecl install redis-5.3.7 \ |
| 66 | +# && pecl install xdebug-3.2.1 \ |
| 67 | +# && docker-php-ext-enable redis xdebug |
| 68 | + |
| 69 | +# Use the default production configuration for PHP runtime arguments, see |
| 70 | +# https://github.com/docker-library/docs/tree/master/php#configuration |
| 71 | +RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" |
| 72 | + |
| 73 | +# Copy the app dependencies from the previous install stage. |
| 74 | +COPY --from=deps app/vendor/ /var/www/html/vendor |
| 75 | +# Copy the app files from the app directory. |
| 76 | +COPY src /var/www/html |
| 77 | + |
| 78 | +# Switch to a non-privileged user (defined in the base image) that the app will run under. |
| 79 | +# See https://docs.docker.com/go/dockerfile-user-best-practices/ |
| 80 | +USER www-data |
0 commit comments