Interpreting Docker Compose Files
Unlock the complete study guide + 1,040 practice questions across 16 full exams.
Bundled into the existing Designing, Deploying and Managing Network Automation Systems premium course — no separate purchase.
14-day money-back guarantee — no questions asked.
Included in this chapter:
- The Compose file: top-level keys and no version
- The image: image, build, and the Dockerfile
- Runtime overrides: environment, command, entrypoint
- Start order and readiness: depends_on
- Reachability: ports, expose, and service DNS
- Networks: the default network, membership, aliases
- Volumes: named vs bind, persistence, read-only
- Legacy keys, restart, and reading the stem
What each Compose key controls
| Question the key answers | Key(s) | What it sets | Classic trap |
|---|---|---|---|
| Source: what image? | `image` / `build` | Pull a prebuilt image, or (with build) build from a Dockerfile per pull_policy and tag it | Thinking image and build cannot both appear |
| Runtime: how does it run? | `environment` / `command` / `entrypoint` | Inject env vars and override the image's default command | Assuming a rebuild is needed to change behavior |
| Reachability: who can reach it? | `ports` / `expose` | Publish HOST:CONTAINER to the host, or expose internally only | Reading ports as CONTAINER:HOST |
| Discovery: how do peers find it? | service name / `networks` | Resolve by service name via embedded DNS on shared networks | Expecting DNS to resolve across disjoint networks |
| Start order: when does it start? | `depends_on` | Order startup relative to peers, not readiness | Assuming it waits until the dependency is ready |
| Storage: what does it mount? | `volumes` (named / bind) | Persist data in a named volume, or map a host path in | Believing `down` deletes named-volume data |
| Lifecycle: how is it kept up? | `restart` | Relaunch on exit or daemon restart per policy | Using `always` where `unless-stopped` is meant |
Decision tree
Cheat sheet
Unlock with Premium — includes all practice exams and the complete study guide.
References
- Compose file reference (Compose Specification top-level elements)
- Compose file: Version and name top-level elements
- Compose Build Specification (build + image, pull_policy)
- Dockerfile reference (FROM, RUN, COPY, EXPOSE, CMD, ENTRYPOINT)
- Define services in Docker Compose (environment, depends_on, ports, expose, aliases, links, restart)
- Control startup and shutdown order in Compose
- Networking in Compose (default <project>_default bridge, embedded DNS, network membership)
- Docker Engine networking (embedded DNS server at 127.0.0.11)
- Compose file: networks top-level element (driver, external)
- Docker volumes (named, Docker-managed persistent storage)
- Docker bind mounts (host-path mounts, read-only)
- Compose file: volumes top-level element
- docker compose down (keeps named volumes; -v removes them)