Typorithm · easy

docker compose

compose-basicsdevopscomposeservicesdepends-on
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn docker compose

0%

Compose

A Compose file describes a multi-container app in one YAML file. Each service is built from a Dockerfile (build) or a prebuilt image, ports publishes them to the host, and depends_on sets start order — one docker compose up brings the whole stack up.

Docker Compose describes a multi-container application in a single YAML file under the services key. Each service becomes one container, configured independently.

A service gets its image either by building one (build pointing at a Dockerfile directory) or by pulling a prebuilt one (image). ports publishes a container port to the host as host:container.

depends_on declares that one service should start after another, so Compose orders startup. A single docker compose up brings the entire stack up, which is ideal for local development.

01

services lists every container in the app.

02

build builds an image; image pulls a prebuilt one.

03

depends_on sets the order services start in.

services:
  web:
    build: .
    ports:
      - "8080:80"
    depends_on:
      - db
  db:
    image: postgres:16

Read the implementation

Connect each part of the code to the concept before you type.

1. Services block

services is the top-level map; each key under it is one container in the app.

services:

2. Build from Dockerfile

build points at a directory with a Dockerfile; Compose builds the image for this service.

build: .

3. Publish a port

ports maps host:container, so localhost:8080 reaches port 80 inside the web container.

- "8080:80"

4. Start order

depends_on makes Compose start the listed services first, controlling startup order.

depends_on:

5. Use an image

image pulls a prebuilt image from a registry instead of building one locally.

image: postgres:16

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

docker compose: Lesson & Practice · Typorithm | ApplyDjinn