World map

 

BM: Baca dalam Bahasa Melayu

World C2: Container Pipelines

Service containers: a test database

You will learn: to give your tests a throwaway Postgres on the runner.

Checked with GitHub Actions 2026-10 on 31 Oct 2026

The problem

Pick an event. Press Run and watch the line.

A pull request runs the tests. They fail: connect ECONNREFUSED 127.0.0.1:5432.

What happened on GitHub

Workflow file .github/workflows/test.yml

name: Test
on:
pull_request:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
- run: npm ci
- run: npm test
env:
DATABASE_URL: postgres://postgres:test@localhost:5432/postgres

The line

Pull request · feature → main

Press Run. The order tests fail: connect ECONNREFUSED 127.0.0.1:5432. Plain words: nobody answers at the database’s door.

Watch

Tap the line that opens the fridge door to the runner.

0 of 1 found

A service container: A helper container, like a test database, that lives only for one job. is a practice fridge wheeled next to the station. GitHub starts it before your steps. It is thrown away after the job.

Try it

Fix the yellow line: give the job a database. Then press Run.

The line is red. Fix the yellow lines, then run again.

What happened on GitHub

Workflow file .github/workflows/test.yml

name: Test
on:
pull_request:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
- run: npm ci
- run: npm test
env:
DATABASE_URL: postgres://postgres:test@localhost:5432/postgres

Yellow: lines 8–8. You can change these.

Pick a fix

The line

Pull request · feature → main

Predict

Why add options: --health-cmd pg_isready?

Pick one answer.

Check

Where does each line go?

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

      You did it!

      You can now give your tests a throwaway database.

      Go deeper (optional)

      test is fine as a password here. The fridge lives for one job only. Real secrets still go in the locked spice box. Job running in a container:? Call the service by its name, db.

      Real rep (optional):

      Real mission

      0 of 3 steps done · Your ticks are saved.