Compose overview

Docker Compose describes a multi-container application in one YAML file, making local development environments repeatable.

Example Compose file

services:

web:

image: php:8.2-apache

ports:

  • "8080:80"

volumes:

  • ./app:/var/www/html

depends_on:

  • db

db:

image: mysql:8.4

environment:

MYSQL_DATABASE: demo

MYSQL_USER: app

MYSQL_PASSWORD: local-only-change-me

MYSQL_ROOT_PASSWORD: local-root-change-me

volumes:

  • mysql_data:/var/lib/mysql

volumes:

mysql_data:

Use local-only credentials. Do not reuse these values in production.

Useful commands

docker compose config

docker compose up -d

docker compose ps

docker compose logs -f web

docker compose down

docker compose down -v also removes named volumes and can delete local database data.

Improve the lab

Add a custom PHP image with required extensions, database health checks, non-root execution where practical and a separate production configuration.