I want to dockerize my php application and deploy it in production. Here is my application structure :
api
|
+-- src
+-- config
+-- vendor
+-- tests
+-- public
I need to embed api/*
in my container, and I'm confused about the best approach.
Here is mine :
A light multi-stage docker image (around 85 mb but can be more optimized)
FROM php:7.4-fpm-alpine AS base WORKDIR /var/www/html ENV COMPOSER_ALLOW_SUPERUSER 1 RUN apk update && \ docker-php-ext-install mysqli tokenizer pdo_mysql && \ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer FROM base AS dev COPY xdebug.ini /usr/local/etc/php/conf.d/xdebug-dev.ini RUN apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS && \ pecl install xdebug-2.9.1 && \ docker-php-ext-enable xdebug && \ touch /tmp/xdebug.log && \ chmod -R 666 /tmp/xdebug.log && \ apk del -f .phpize-deps
A mounted volume (docker-compose.yml)
api: volumes: - ./api:/var/www/html command: composer install && php-fpm;
I saw a lot of docker images using COPY ..
instruction in Dockerfile
instead of volumes. I believe COPY
is great to copy small config files (or a small build for compiled languages), but it's not optimized to keep the images small (basic rule with docker).
Am I missing something? For example, is it bad practice to handle volumes from outside the dev environment ?