Multi-service apps with Docker Compose
You describe apps made of a web tier, a database and a cache in one file, and move and update them across environments.
Level 201 · 15 lessons · 12 practice labs
Lessons
The Compose file
- Why Compose: the whole app in one command
- Services, images and the build section
- Ports, environment variables and the .env file
- Volumes and networks in Compose
- Short task: bring up web, app and database from one file
Starting up healthy
- depends_on and health checks
- Logs, exec and restarting one service with Compose
- Scaling a service and putting a proxy in front
- Short task: fix an app that starts before its database is ready
Environments
- Override files: development and production
- Optional services with profiles
- Secrets and configs in Compose
- Updating the app and rolling back
- Short task: run a separate staging copy of the same app
Wrap-up
- Capstone: build a blog stack with a monitoring dashboard using Compose
Practice labs
- A Compose file with broken indentation: Get the Compose file that won’t load because of indentation and interpolation errors through docker compose config cleanly, and bring the services up.
- Services that can’t find each other: Fix the network definitions of the app and database services attached to different networks, and show from the logs that the app connects to the database by service name.
- A Compose file from running containers: Inspect three containers started by hand with docker run, write an equivalent Compose file, replace them with the Compose stack and prove it behaves the same.
- A service that’s always unhealthy: Fix the health check that stays unhealthy because it calls a tool missing from the image, and show the service as healthy in docker compose ps.
- Refresh only the app: Roll out the app code change by rebuilding and restarting only that service, and show the database container’s uptime did not change.
- Migration job, cache and queue order: Set the start order of database, schema migration job, cache and worker services with health and completion conditions, and prove nothing errors when starting from scratch.
- An .env file that’s ignored: Find why the .env file isn’t read in a stack whose variables come up empty, fix the project folder or file path and show with docker compose config that the values are filled.
- Live code in development: Write a development override file for Orchid Hotel’s booking app that bind-mounts the code, and show with the merged config output that the production setup is unaffected.
- Get the password out of the environment: Move the database password from an environment variable to a Compose secret, make the app read it from the file and prove the password no longer shows in docker inspect.
- A port clash when scaling: Rework the service that can’t scale because of a fixed host port, put the existing reverse proxy in front and show three replicas receiving requests.
- Admin tools on demand: Define the database admin UI and debug tools so they start only when a profile is selected, and show they don’t run on a normal start.
- Rolling back a bad update: Return the app that fails its health check after an update to a new image tag to the previous version without data loss, and document the steps in a short note.
About this course
You describe apps made of a web tier, a database and a cache in one file, and move and update them across environments.
What you will learn
- The Compose file
- Starting up healthy
- Environments
- Wrap-up
Prerequisites
Finishing the level 101 courses of the same path, or knowing those topics, is enough.
Lab environment
Lessons run in your own Kali Linux terminal in the browser, connected to a private lab network. Nothing to install.
Frequently asked questions
- Is this course right for my level?
- The course is at level 201; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.