What Docker Compose solves
Docker Compose v2 describes a docker compose multi-container app in a single declarative file: which images to run, how they talk to each other over the network, and which data survives a restart. Instead of chaining several loose docker run calls, you define the whole stack once and bring it up, inspect it, and tear it down with a handful of subcommands on Docker’s own CLI (docker compose, no hyphen: the v2 plugin that replaced the old Python docker-compose).
The shape of a compose.yaml file
A typical compose.yaml has three blocks: services (one container per service, with its image, ports and variables), networks (the networks those services share) and volumes (named storage Docker manages for you). Our lab defines a web service running Nginx and a cache service running Redis, both on the same labnet network, with Nginx’s content stored in a named volume instead of a bind mount tied to a host path.
How services find each other
Alongside the services, Compose creates a custom bridge network with an embedded DNS resolver: every container can reach the others by service name (cache, web) without knowing its internal IP, something Docker’s default bridge network doesn’t give you. It’s the same principle behind our Redis on Docker and Portainer on Docker Compose guides whenever several containers need to talk to each other.
From docker compose up to docker compose down
The whole lifecycle fits in four commands: docker compose up -d creates the network, the volume, and starts the containers in the order depends_on sets; docker compose ps and docker compose logs confirm they’re healthy; docker compose exec drops you inside a specific service; and docker compose down -v tears it all down, volume included. For production, add healthchecks and restart policies to each service. The full compose file reference lives in the official Docker Compose documentation, the v2 plugin’s code is public at github.com/docker/compose, and the Redis commands used in the lab are documented at redis.io.
FAQ
What is Docker Compose v2?
It is the official Docker CLI plugin invoked as docker compose (no hyphen), replacing the old Python-based docker-compose. It reads a compose.yaml file and orchestrates several containers, their network and their storage as a single unit.
How do services talk to each other in Docker Compose?
Compose creates its own bridge network for the project with an embedded DNS resolver: any container can reach another using its service name (for example cache) as if it were a hostname, with no need to know or hardcode its internal IP.
Why use a named volume instead of a bind mount?
A named volume is managed by Docker: it doesn't depend on a specific host path, it survives a plain docker compose down (without -v), and it's portable across machines. A bind mount ties the container to an exact host folder, handy for development but less portable.
What's the difference between docker compose stop and docker compose down?
docker compose stop halts the containers but leaves them created, along with the network and volumes, ready to resume with start. docker compose down goes further: it removes the containers and the network, and with the -v flag it also deletes the project's named volumes.