Typorithm · medium

Volumes, Env & Networks

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

Step 1 of 8 · intro card

Learn Volumes, Env & Networks

0%

Compose

environment sets container env vars (or use env_file), named volumes declared at the top level persist data across restarts, and Compose puts every service on a default network so they resolve each other by service name.

environment injects environment variables into a container as key: value pairs; for many values you can point env_file at a .env file instead.

A named volume declared at the top-level volumes key persists data outside the container's lifecycle. Mounting it (dbdata:/var/lib/postgresql/data) keeps the database intact across restarts and re-creations.

Compose attaches all services to a default network, so they reach each other by service name — another container connects to this database simply as the host db. Healthchecks and profiles refine this further.

01

environment sets env vars; env_file loads many at once.

02

Named volumes persist data across restarts.

03

Services resolve each other by service name on the default network.

services:
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: secret
    volumes:
      - dbdata:/var/lib/postgresql/data
volumes:
  dbdata:

Read the implementation

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

1. Env vars

environment sets environment variables inside the container as key: value pairs.

environment:

2. An env var

Postgres reads POSTGRES_PASSWORD on first boot to set the database password.

POSTGRES_PASSWORD: secret

3. Mount a volume

This mounts the named volume dbdata at the container path where Postgres stores its data.

- dbdata:/var/lib/postgresql/data

4. Declare the volume

Named volumes must be declared at the top level so Compose creates and manages them.

volumes:
  dbdata:

5. The service image

Other services reach this one by its service name, db, over the default network.

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.

Volumes, Env & Networks: Lesson & Practice · Typorithm | ApplyDjinn