Docker Compose: service names, ports, a named volume and exec
Start an app and its data store together, see why services find each other by name, keep data across a restart, and run a command inside one service.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a market street with a gate and a store room. The stalls call each other by the name on the sign. Visitors from the road use the gate number, not the stall's private door. A store room behind the street keeps stock when the stalls are packed away at night.
The street is the . The sign is the service name. The store room is a named volume. Stepping into a stall to look at a box is exec.
Tom, a tester at Daily List, a to-do list app, needs the app and its data store up together.
What it is: Docker Compose starts several containers from one file, usually compose.yaml. A Compose network lets services find each other by name, and a keeps data after docker compose down. To is to run a command inside a service that is already up. One docker run is the neighbour, and it starts a single container. Compose starts the whole set and wires the names.
Why it matters: A Daily List test needs the app and a data store together. It fails if Tom starts only one of them. It also fails if the app looks for a laptop address that changes. Compose gives a stable service name, a host port for the browser and a volume so a restart does not wipe the rows. Exec lets him look inside when a service is up but the page is wrong.
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB A market street with stalls, a street gate and a store room.
- Street
- Gate
- Storeroom
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The street the stalls share | The Compose network |
| The name on a stall sign | The service name |
| The gate to the road outside | The host port |
| The store room behind the street | The named volume |
WHERE THIS PICTURE STOPS
- A sign is painted once, but a service name is set in the file.
- A gate faces the road, but services reach each other inside the street.
- A store room can be cleared by hand, and down with the volumes option does that.
HOOK
Street, gate, store room.
TELL A FRIEND
Stalls on a street with a gate and a store room.
OFTEN MIXED UP WITH Docker part 2: write a Dockerfile and build your own test image. That topic builds one image from a Dockerfile. This one starts several services together and keeps their data.
PRACTISE AND KEEP
Sources for this topic — 5 sources
- Market practice
Networking in Compose (Docker documentation) ↗ — Docker · Docker docs on networking in Compose: Compose creates a default network named after the project and attaches every service to it, a service name works as a host name on that network, and container addresses can change so names are the safe choice
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Docker Compose Quickstart (Docker documentation) ↗ — Docker · Docker Compose quickstart: a compose.yaml with a web service and a cache store service, host port 8000 maps to container port 5000, and a named volume registered under the top-level volumes key survives docker compose down and up unless the v option is added
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
docker compose exec and docker compose down (Docker reference) ↗ — Docker · Docker reference: docker compose exec runs a command in an already-running container in the form exec, options, service, command, and docker compose down removes containers and networks and removes volumes only when the v option is given
Found through a web search; the page was not opened (search excerpt, page not opened). Version: Web page, no edition number. Licence terms were not read, so put it in your own words and do not quote it. Open the page and confirm what it says before relying on any detail.
- Market practice
Control startup order in Compose ↗ — Docker · Running is not ready; healthcheck and depends_on service_healthy.
Publisher primary source opened and relevant sections read on 6 November 2026 for the Agile/DevOps domain analysis. Original explanations are used; no extensive source text is copied. Also read for the CI/Containers analysis; live documentation does not establish the version installed in a learner environment.
- Market practice
Docker volumes ↗ — Docker · Mounted-path persistence beyond container removal; explicit volume deletion.
Actual primary documentation body read during the complete V30 domain analysis before implementation. Live documentation access-dated; no claim this version is installed in the learner environment. No artwork copied by this content change.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.