Skip to content

Instantly share code, notes, and snippets.

@dehsilvadeveloper
Last active January 9, 2025 12:27
Show Gist options
  • Save dehsilvadeveloper/e2a6198c7fa01b4374a065623fb112eb to your computer and use it in GitHub Desktop.
Save dehsilvadeveloper/e2a6198c7fa01b4374a065623fb112eb to your computer and use it in GitHub Desktop.
Dockerfile for PHP 8.2. Can be used to build environment for Laravel 10 applications.
# Defining base image
FROM php:8.2-fpm-alpine
# Setting arguments
ARG user=developer
ARG uid=1000
# Steps of this layer:
# - Install system dependencies
# - Install and enable PHP extensions
# - Remove packages that are only needed for build, not for run-time
# - Clear APK cache and temporary files
RUN apk update && apk --no-cache --virtual add \
autoconf \
bash \
build-base \
curl \
gd \
icu \
icu-dev \
iputils-ping \
libmcrypt-dev \
libjpeg-turbo \
libpng-dev \
libxml2-dev \
libzip-dev \
net-tools \
oniguruma-dev \
openssl \
openssl-dev \
unzip \
zip \
&& pecl channel-update pecl.php.net \
&& pecl install -o -f redis pcov \
&& docker-php-ext-install bcmath exif gd intl mbstring opcache pcntl pdo pdo_mysql xml zip \
&& docker-php-ext-enable redis pcov \
&& apk del autoconf build-base icu-dev libmcrypt-dev libpng-dev libxml2-dev libzip-dev oniguruma-dev openssl-dev \
&& rm -rf /var/cache/apk/* \
&& rm -rf /tmp/pear
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN addgroup -g $uid $user \
&& adduser -u $uid -G $user -h /home/$user -s /bin/bash -D $user \
&& addgroup $user root \
&& addgroup $user www-data \
&& mkdir -p /home/$user/.composer \
&& chown -R $user:$user /home/$user
# Set working directory
WORKDIR /var/www
# Copy custom.ini of PHP to the final directory
COPY ./custom.ini /usr/local/etc/php/conf.d/custom.ini
# Remove possible unnecessary directory (to avoid errors with symbolic link) and create symbolic link
RUN rm -rf /var/www/html \
&& ln -s public html
# Define user been used
USER $user
# Expose port
EXPOSE 9000
[PHP]
zend.exception_ignore_args = off
expose_php = off
max_execution_time = 30
max_input_vars = 1000
post_max_size = 100M
upload_max_filesize = 100M
memory_limit = 256M
error_reporting = E_ALL
display_errors = on
display_startup_errors = on
log_errors = on
error_log = /dev/stderr
default_charset = UTF-8
[Date]
date.timezone = "America/Sao_Paulo"
[mysqlnd]
mysqlnd.collect_memory_statistics = off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment