Originally published on docker.learnio.dev — part of the Docker fundamentals course. View this lesson on the original site.

One main job per container

Docker stays understandable when each running container has a clear role.

flowchart LR
    web["web container"] --> app["app container"]
    app --> db["database"]
    worker["worker container"] --> db

For a typical PHP app that might mean: web server, PHP-FPM, queue worker, and database as separate containers — sometimes sharing one image with different commands.

When one container is not enough

Hand-typing eight docker run commands does not scale. Docker Compose describes the whole stack in one file:

services:
  app:
    image: php:8.3-cli
  db:
    image: mysql:8.4
docker compose up
docker compose ps
docker compose down

You will use Compose heavily from chapter 7 onward. For now, remember the idea: one file, many services.

If it goes wrong

  • One giant container doing web + worker + cron: hard to debug and restart in parts.
  • Skipping Compose too early: fine for chapter 1; painful for a real multi-service app.

Remember

One running container, one main role — Compose wires the roles together.

From Docker fundamentals — Install Docker, see the value, and learn the basics