-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
112 lines (98 loc) · 3.92 KB
/
Copy pathDockerfile
File metadata and controls
112 lines (98 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# syntax=docker/dockerfile:1
# =============================================================================
# middagtec/php-base — Shared PHP-FPM base image
#
# Build arg:
# PHP_VERSION (default: 8.4)
#
# Tags per version:
# middagtec/php-base:<ver>-fpm (production)
# middagtec/php-base:<ver>-fpm-dev (production + Xdebug)
#
# Usage:
# FROM middagtec/php-base:8.4-fpm
# COPY --from=builder /build/ /var/www/html/
# =============================================================================
ARG PHP_VERSION=8.4
# =============================================================================
# Stage 1: production — PHP-FPM with all common extensions
# =============================================================================
FROM php:${PHP_VERSION}-fpm AS production
ARG PHP_VERSION
LABEL maintainer="MIDDAG <paulo@middag.com.br>"
LABEL org.opencontainers.image.source="https://github.com/middag-io/php-base"
LABEL org.opencontainers.image.description="PHP ${PHP_VERSION}-FPM base image with common extensions for WordPress and Moodle"
# System dependencies for PHP extensions + tools
RUN apt-get update && apt-get install -y --no-install-recommends \
# PHP extension build deps (only for extensions not in base image)
libfreetype6-dev \
libicu-dev \
libjpeg62-turbo-dev \
libonig-dev \
libpng-dev \
libzip-dev \
libwebp-dev \
libavif-dev \
libgmp-dev \
libmpdec-dev \
libpq-dev \
libldap2-dev \
libmagickwand-dev \
# Runtime tools
ghostscript \
graphviz \
mariadb-client \
redis-tools \
# GD with full format support
&& docker-php-ext-configure gd \
--with-freetype \
--with-jpeg \
--with-webp \
--with-avif \
&& docker-php-ext-configure ldap \
# Extensions already in php:X.Y-fpm base: curl, dom, mbstring, sodium, xml
# opcache is always built-in starting PHP 8.5 (cannot be installed as shared)
&& docker-php-ext-install -j"$(nproc)" \
bcmath \
exif \
gd \
gmp \
intl \
ldap \
mysqli \
pcntl \
pdo_mysql \
pdo_pgsql \
pgsql \
soap \
zip \
&& if [ "$(php -r 'echo PHP_MINOR_VERSION;')" -lt 5 ]; then \
docker-php-ext-install opcache; \
fi \
# PECL extensions
&& pecl install redis decimal imagick apcu xdebug \
&& docker-php-ext-enable redis decimal imagick apcu \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
&& rm -rf /var/lib/apt/lists/* /tmp/pear
# OPcache defaults (projects can override via their own .ini)
COPY config/opcache.ini /usr/local/etc/php/conf.d/opcache-defaults.ini
# PHP-FPM ping/status for health checks
RUN echo "[www]" > /usr/local/etc/php-fpm.d/zz-healthcheck.conf \
&& echo "pm.status_path = /status" >> /usr/local/etc/php-fpm.d/zz-healthcheck.conf \
&& echo "ping.path = /ping" >> /usr/local/etc/php-fpm.d/zz-healthcheck.conf \
&& echo "ping.response = pong" >> /usr/local/etc/php-fpm.d/zz-healthcheck.conf
# Health check script
COPY config/healthcheck.sh /usr/local/bin/healthcheck
RUN chmod +x /usr/local/bin/healthcheck
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD ["healthcheck"]
WORKDIR /var/www/html
# =============================================================================
# Stage 2: development — adds Xdebug (pre-compiled in production stage)
# =============================================================================
FROM production AS development
RUN docker-php-ext-enable xdebug
# Xdebug defaults (projects can override via their own xdebug.ini)
COPY config/xdebug.ini /usr/local/etc/php/conf.d/xdebug-defaults.ini
# OPcache: validate timestamps in dev (pick up file changes without restart)
RUN echo "opcache.validate_timestamps = 1" > /usr/local/etc/php/conf.d/opcache-dev.ini