Docker Compose
The compose.yaml file and its keys (services, image, build, ports, environment, volumes, depends_on, networks, restart, healthcheck), the default network and name resolution by service name, the up, down, ps, logs and exec commands.
- 25 cards
- 5 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
- Understand
A few cards from the deck
Docker Compose: what is it?
Show the answer
A tool that describes in a single file several containers forming an application, with their networks and volumes, and drives them with one command.
It replaces a pile of long
docker runcommands with a versioned file:docker compose up -dis enough to start everything.Which command starts all the file's services in the background?
docker compose up -ddocker compose start -ddocker compose run -ddocker compose build -d
Show the answer
docker compose up -dupcreates (network, volumes, containers) then starts;-dreturns control.startonly restarts containers that already exist, andbuildonly builds images.docker compose downdeletes the containers and the network; adding the … option also deletes the … declared in the file.Show the answer
docker compose downdeletes the containers and the network; adding the -v option also deletes the volumes declared in the file.Without
-v, the named volumes' data survives adown: that is what lets the application be re-created without losing the database.compose.yaml: what is it?
Show the answer
A YAML file whose root key
serviceslists the application's containers, each with its image, ports, variables and volumes.In YAML, structure comes from indentation, with spaces and never tabs: a two-space shift changes the meaning or makes the file invalid.
The API returns
connect ECONNREFUSED 127.0.0.1:5432although thedbcontainer is running. What is the probable cause, and the fix?- Port 5432 is not published; add
ports: ["5432:5432"]to thedbservice - The API targets
localhost, so itself; replace the host with the service name,db - The database is not on the same network as the API; declare a
backendnetwork for each - The API starts too fast; add
restart: alwaysso that it retries
Show the answer
The API targets
localhost, so itself; replace the host with the service name,db127.0.0.1 is the API container's address. Between Compose services there is no need to publish a port: the default network connects them, and only the service name lets them reach each other.
- Port 5432 is not published; add