-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
96 lines (72 loc) · 2.83 KB
/
Copy pathDockerfile
File metadata and controls
96 lines (72 loc) · 2.83 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
# syntax=docker/dockerfile:1.4
# ==============================================================================
# 1. Base PHP Image (shared system dependencies & extensions)
# ==============================================================================
FROM php:8.5-fpm-alpine AS php_base
# Install system dependencies
RUN apk add --no-cache \
bash \
ca-certificates \
icu-dev \
libzip-dev \
libpng-dev \
libjpeg-turbo-dev \
libwebp-dev \
freetype-dev \
supervisor
# Configure and install PHP extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
&& docker-php-ext-install -j$(nproc) \
pdo_mysql \
intl \
zip \
gd
# Install APCu
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
&& pecl install apcu \
&& docker-php-ext-enable apcu \
&& apk del .build-deps
# Copy php.ini production configuration
COPY docker/php/conf.d/app.ini $PHP_INI_DIR/conf.d/app.ini
# Install Composer
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
WORKDIR /srv/app
# ==============================================================================
# 2. Builder Stage (Installs production dependencies & compiles assets)
# ==============================================================================
FROM php_base AS php_builder
ENV APP_ENV=prod
ENV APP_DEBUG=0
# Copy application source code
COPY . .
# Install Composer dependencies (optimized for production)
RUN composer install --no-dev --no-interaction --optimize-autoloader --classmap-authoritative
# Warm up Symfony cache and build assets
RUN php bin/console cache:clear \
&& php bin/console assets:install public \
&& php bin/console importmap:install \
&& php bin/console asset-map:compile
# ==============================================================================
# 3. Final Production PHP-FPM Image
# ==============================================================================
FROM php_base AS php_prod
ENV APP_ENV=prod
ENV APP_DEBUG=0
# Copy production-ready source and vendor from builder
COPY --from=php_builder --chown=www-data:www-data /srv/app /srv/app
# Set appropriate permissions for Symfony cache and log directories
RUN mkdir -p var/share var/log var/cache \
&& chown -R www-data:www-data var
USER www-data
EXPOSE 9000
CMD ["php-fpm"]
# ==============================================================================
# 4. Final Production Nginx Image (with built static assets embedded)
# ==============================================================================
FROM nginx:alpine AS nginx_prod
# Copy custom Nginx configuration
COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf
# Copy public directory containing compiled assets from the builder stage
COPY --from=php_builder /srv/app/public /srv/app/public
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]