Top-level volumes

Declare persistent Compose storage

Lesson 15 of 20 · 12 min · Module 5: Readiness and runtime boundaries

Describe persistent storage as part of the stack contract.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Separate declaration from attachment
  • Preserve the intended destination

The idea

Compose describes services and their relationships as YAML mappings and sequences. Read the whole service graph, including access and storage boundaries.

services:
  worker:
    image: notes:1.0
    volumes: ["worker-data:/data"]
volumes:
  worker-data: {}

01Separate declaration from attachment

The top-level volumes mapping declares a named volume. A service mount attaches it to the path the application uses.

02Preserve the intended destination

The application expects /data. Mounting the same volume at an unrelated path does not automatically move the application storage there.

03Plan a recovery procedure

Persistence survives routine replacement, but a restore test is still needed for data loss. The Infrastructure & Operations course practices that separate responsibility.

Your turn

Define api with image notes:1.0 and volume notes-data mounted at /data. Declare notes-data in the top-level volumes mapping.

What the checks look for

  • Declares the named volume
  • Mounts it at the application data path
Try it in the editor →

Take this with you

Make the storage contract explicit and test recovery separately.

Go a little further

Rewrite the mount using Compose long syntax.

Learn Docker & Containers for free

20 short lessons with real code and instant checks.

See the whole course →