Production-Ready Docker Compose Boilerplate for Nginx, PHP-FPM, and MySQL
A clean, modular Docker Compose configuration to spin up a fully isolated PHP, Nginx, and MySQL development environment in seconds.
Overview & Problem Matrix
Setting up a local development environment stack (such as traditional LEMP or LAMP engines) directly on your base host operating system frequently leads to system configuration conflicts, port collisions, and mismatched version runtimes across deployment teamsāresulting in the classic "it works on my machine" problem.
Manually downloading, linking, and exposing isolated container instances via independent Docker CLI command parameters is highly inefficient and hard to track over long project lifecycles.
Implementation Guide & Setup Steps
To orchestrate this multi-service container environment framework seamlessly, complete these deployment operations:
- Arrange the Local Directory Workspace: Create a core project directory containing a dedicated web server root directory labeled
/srcto hold your entry script files, alongside annginx.confrouting configuration layer:
$ mkdir -p my-app/src
- Initialize the Cluster Orchestration: Save the configuration architecture schema below as
docker-compose.ymldirectly in the root of your newly created project directory:
$ touch my-app/docker-compose.yml
- Boot the Shared Network Background Daemons: Navigate into your folder and launch the environment stack. Docker will automatically pull images, configure virtual subnets, map shared storage paths, and spin up services:
$ cd my-app $ docker compose up -d
- Audit Container Connectivity Status: Verify your isolated runtime environment states to ensure all dependencies are operating cleanly:
$ docker compose ps
# Access your dynamic application layer directly via your web browser node: # URL: http://localhost:8080
version: '3.8'
services: # 1. Nginx Web Server Service Routing Engine webserver: image: nginx:alpine container_name: htd-webserver restart: unless-stopped ports:
- "8080:80"
volumes:
- ./src:/var/www/html
- ./nginx.conf:/etc/nginx/conf.d/default.conf
networks:
- htd-network
depends_on:
- php-fpm
# 2. PHP-FPM Processor Service Runtime Engine # NOTE: If your source code connects to the database service via PDO, make sure to # append native extensions (docker-php-ext-install pdo pdo_mysql) using a custom Dockerfile layer. php-fpm: image: php:8.2-fpm-alpine container_name: htd-php restart: unless-stopped volumes:
- ./src:/var/www/html
networks:
- htd-network
# 3. MySQL Database Storage Instance database: image: mysql:8.0 container_name: htd-database restart: unless-stopped environment: MYSQL_DATABASE: app_db MYSQL_USER: db_user MYSQL_PASSWORD: secure_dev_password MYSQL_ROOT_PASSWORD: secure_root_password ports:
- "33060:3306"
volumes:
- dbdata:/var/lib/mysql
networks:
- htd-network
networks: htd-network: driver: bridge
volumes: dbdata: driver: local
Community Engineering Notes
No technical implementations have been appended yet.