Files
laravel-test/docker/php/Dockerfile
2026-03-30 19:15:13 +02:00

94 lines
4.8 KiB
Docker

# ────────────────────────────────────────────────────────────────
# Immagine base: PHP 8.2 in modalità FPM (FastCGI Process Manager)
# FPM è la modalità usata in produzione con Nginx.
# ────────────────────────────────────────────────────────────────
FROM php:8.2-fpm
# Argomenti di build (puoi sovrascriverli con --build-arg)
ARG USER_ID=1000
ARG GROUP_ID=1000
# ────────────────────────────────────────────────────────────────
# 1. Dipendenze di sistema e estensioni PHP necessarie a Laravel
# ────────────────────────────────────────────────────────────────
RUN apt-get update && apt-get install -y \
# Strumenti base
git \
curl \
unzip \
zip \
# Librerie per le estensioni PHP
libpng-dev \
libonig-dev \
libxml2-dev \
libzip-dev \
libpq-dev \
libredis-dev \
# Per generazione immagini/PDF (opzionale ma comune)
libfreetype6-dev \
libjpeg62-turbo-dev \
# Pulizia cache apt per ridurre dimensione immagine
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# ────────────────────────────────────────────────────────────────
# 2. Estensioni PHP
# docker-php-ext-install → estensioni native PHP
# pecl install → estensioni da PECL (es. Redis)
# ────────────────────────────────────────────────────────────────
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install \
pdo_mysql \
mbstring \
exif \
pcntl \
bcmath \
gd \
zip \
xml \
opcache
# Estensione Redis via PECL
RUN pecl install redis \
&& docker-php-ext-enable redis
# ────────────────────────────────────────────────────────────────
# 3. Composer: gestore dipendenze PHP
# Lo copiamo dall'immagine ufficiale di Composer (multi-stage)
# ────────────────────────────────────────────────────────────────
COPY --from=composer:2.7 /usr/bin/composer /usr/bin/composer
# ────────────────────────────────────────────────────────────────
# 4. Utente non-root per sicurezza
# Usiamo lo stesso UID/GID del tuo utente host per evitare
# problemi di permessi sui file montati con volume.
# ────────────────────────────────────────────────────────────────
RUN groupmod -o -g ${GROUP_ID} www-data \
&& usermod -o -u ${USER_ID} -g www-data www-data
# ────────────────────────────────────────────────────────────────
# 5. Directory di lavoro e permessi
# ────────────────────────────────────────────────────────────────
WORKDIR /var/www
RUN mkdir -p \
storage/app/public \
storage/framework/cache/data \
storage/framework/sessions \
storage/framework/testing \
storage/framework/views \
storage/logs \
bootstrap/cache \
&& chown -R www-data:www-data /var/www
# ────────────────────────────────────────────────────────────────
# 6. Script di avvio
# ────────────────────────────────────────────────────────────────
COPY docker/php/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
USER www-data
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["php-fpm"]