World map

 

BM: Baca dalam Bahasa Melayu

World D4: Set Meals

Dev vs prod: override files

You will learn: to run one app two ways, with a shared file and small extras.

Checked with Docker Engine 29 on 31 Oct 2026

The problem

Your laptop wants quick edits. The shop’s server wants to stay up by itself. One file can’t say both. Sort each wish.

Drag a card into a box. Or tap the card, then tap the box.

        Watch

        # compose.override.yaml
        services:
          web:
            volumes:
              - ./web:/usr/share/nginx/html:ro
        The laptop's web folder is mounted into web, so the new menu shows at once. Docker transcript: $ docker compose up -d [+] up 5/5 ✔ Network kedai-kancil_default Created 0.1s ✔ Volume kedai-kancil_db-data Created 0.0s ✔ Container kedai-kancil-web-1 Started 0.3s ✔ Container kedai-kancil-api-1 Started 0.3s ✔ Container kedai-kancil-db-1 Started 0.3s $ echo "<h1>Kedai Kancil: new menu</h1>" > web/index.html $ curl -s localhost:8080 <h1>Kedai Kancil: new menu</h1>

        Your laptop~/kedai-kancil

        • No open hatches

        Lunchboxes (containers)

        • No containers yet

        Frozen packs (images)

        • kedai-kancil-api:latest6 layers · 244MB
        • kedai-kancil-web:latest9 layers · 92.6MB
        • nginx:1.30-alpine8 layers · 93.5MB
        • node:24-alpine4 layers · 244MB
        • postgres:18-alpine9 layers · 433MB
        • redis:8-alpine7 layers · 162MB

        0 containers (0 running), 6 images, 0 lockers.

        Shared things stay in compose.yaml. Laptop extras go in compose.override.yaml. Compose reads this override file: A second compose file laid on top of the first. compose.override.yaml loads by itself; others need -f. by itself and lays it on top.

        Predict

        Two files set the same key. The first says one value, the later file says another. Which one wins?

        Pick one answer.

        Try it

        Start the server version: compose.yaml plus compose.prod.yaml. Name both files with -f, base first.

        Your laptop~/kedai-kancil

        • No open hatches

        Lunchboxes (containers)

        • No containers yet

        Frozen packs (images)

        • kedai-kancil-api:latest6 layers · 244MB
        • kedai-kancil-web:latest9 layers · 92.6MB
        • nginx:1.30-alpine8 layers · 93.5MB
        • node:24-alpine4 layers · 244MB
        • postgres:18-alpine9 layers · 433MB
        • redis:8-alpine7 layers · 162MB

        0 containers (0 running), 6 images, 0 lockers.

        Check

        With -f, the dev override is skipped. The laptop edit doesn't reach the server: the old page shows. Docker transcript: $ docker compose -f compose.yaml -f compose.prod.yaml up -d [+] up 5/5 ✔ Network kedai-kancil_default Created 0.1s ✔ Volume kedai-kancil_db-data Created 0.0s ✔ Container kedai-kancil-web-1 Started 0.3s ✔ Container kedai-kancil-api-1 Started 0.3s ✔ Container kedai-kancil-db-1 Started 0.3s $ echo "<h1>Kedai Kancil: new menu</h1>" > web/index.html $ curl -s localhost:8080 <h1>Kedai Kancil</h1>

        Your laptop~/kedai-kancil

        • No open hatches

        Lunchboxes (containers)

        • No containers yet

        Frozen packs (images)

        • kedai-kancil-api:latest6 layers · 244MB
        • kedai-kancil-web:latest9 layers · 92.6MB
        • nginx:1.30-alpine8 layers · 93.5MB
        • node:24-alpine4 layers · 244MB
        • postgres:18-alpine9 layers · 433MB
        • redis:8-alpine7 layers · 162MB

        0 containers (0 running), 6 images, 0 lockers.

        Why the old page? With -f, Compose reads only the files you name. No dev mount, so the page comes from the image.

        You did it!

        You can now run one app two ways: dev and prod.

        Go deeper (optional)

        How files merge: one value (like image) is replaced. Lists like ports are added together. environment merges by name. volumes merge by the path inside the box. Dry run the mix before you start it: docker compose -f compose.yaml -f compose.prod.yaml config.

        Real mission

        1. docker compose config
        2. docker compose -f compose.yaml -f compose.prod.yaml config

        0 of 3 steps done · Your ticks are saved.