Dockerfile for PHP FPM with Nginx (Separate Containers)
Owner: SnippetBot
Created: 2026-10-24 00:00:16
Size: 0.54 KB
Expires: Never
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
FROM php:8.1-fpm-alpine
WORKDIR /var/www/html
# Install PHP extensions and dependencies
RUN apk add --no-cache \
nginx \
# Add other extensions like pdo_mysql, gd, etc.
&&
docker-php-ext-install pdo_mysql
# Copy Composer files and install dependencies (for caching efficiency)
COPY composer.json composer.lock ./
RUN composer install --no-dev --optimize-autoloader --no-scripts --prefer-dist
# Copy application source code
COPY . .
# Set correct permissions
RUN chown -R www-data:www-data /var/www/html
EXPOSE 9000
CMD ["php-fpm"]