0PricingLogin
PHP Academy · Lesson

Docker Compose for Local Stacks

Run PHP, a database and cache together locally.

Local Stacks with Compose

Real PHP apps are never just PHP — they need a database, a cache, sometimes a queue and a mail catcher. Docker Compose declares all of these as services in one file and wires them onto a shared network so they reach each other by name.

This lesson builds a full local stack: PHP-FPM + nginx + MySQL + Redis, with volumes, healthchecks, and dependency ordering.

Service Skeleton

A Compose file lists services under services:. Each can build from a Dockerfile or pull an image. Compose creates a default network where every service is reachable by its key — your PHP app connects to MySQL at host db, not localhost.

services:
  app:
    build:
      context: .
      target: dev          # multi-stage dev target
    volumes:
      - ./:/app            # live code mount
    depends_on:
      db:
        condition: service_healthy
  db:
    image: mysql:8.4
  redis:
    image: redis:7-alpine

All lessons in this course

  1. Containerizing a PHP Application
  2. Multi-Stage Builds and Optimization
  3. Docker Compose for Local Stacks
  4. CI/CD with GitHub Actions
← Back to PHP Academy