Files
php-alpine-image/Dockerfile

83 lines
1.9 KiB
Docker

# --- Stage 1: Build PHP ---
FROM alpine:3.22 AS builder
ENV PHP_VERSION=8.5.0
# Build dependencies
RUN apk add \
build-base autoconf bison re2c \
curl tar \
libxml2-dev openssl-dev sqlite-dev zlib-dev pcre2-dev libzip-dev oniguruma-dev \
postgresql-dev \
freetype-dev libpng-dev libjpeg-turbo-dev libwebp-dev \
imap-dev krb5-dev
WORKDIR /tmp
# Download + extract
RUN curl -fSL https://www.php.net/distributions/php-$PHP_VERSION.tar.gz -o php.tar.gz \
&& tar -zxf php.tar.gz
WORKDIR /tmp/php-$PHP_VERSION
# Configure static PHP build
RUN ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php \
--with-config-file-scan-dir=/usr/local/php/conf.d \
--enable-fpm \
--with-fpm-user=php \
--with-fpm-group=php \
--enable-mbstring \
--enable-opcache \
--with-pcre2 \
--with-zlib \
--with-openssl \
--with-curl \
--with-zip \
--with-xml \
--with-sqlite3 \
--with-pdo-sqlite \
--with-pdo-pgsql \
--with-pgsql \
--with-gd \
--with-jpeg \
--with-webp \
--with-freetype \
--with-imap \
--with-imap-ssl
RUN make -j$(nproc) && make install
# PHP production config
RUN cp php.ini-production /usr/local/php/php.ini
# Cleanup
RUN rm -rf /tmp/* /var/cache/apk/*
# --- Stage 2: Runtime ---
FROM alpine:3.22
# Runtime libraries only
RUN apk add \
libxml2 openssl sqlite-libs zlib libzip pcre2 oniguruma \
postgresql-libs \
freetype libpng libjpeg-turbo libwebp \
imap krb5-libs
RUN addgroup -S php && adduser -S -D -H -G php php
RUN mkdir -p /usr/local/php/conf.d /var/run/php
# Copy compiled PHP
COPY --from=builder /usr/local/php /usr/local/php
EXPOSE 9000
USER php
CMD ["/usr/local/php/sbin/php-fpm", "--nodaemonize"]
# Healthcheck
HEALTHCHECK --interval=30s --timeout=3s --retries=3 CMD /usr/local/php/bin/php-fpm -t >/dev/null 2>&1 || exit 1