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.
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.
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.
The line
Pull request · feature → main
Hint
The tests call Postgres on localhost, port 5432.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.
Bahasa Melayu
Tekan Run. Ujian pesanan gagal: connect ECONNREFUSED 127.0.0.1:5432. Maksudnya: tiada siapa jawab di pintu pangkalan data.
Service container ialah peti sejuk latihan yang ditolak ke sebelah stesen. GitHub hidupkannya sebelum langkah anda. Ia dibuang selepas job.
Baiki baris kuning: beri job ini pangkalan data. Kemudian tekan Run.
Kenapa tambah options: --health-cmd pg_isready?
Setiap baris ini pergi ke mana?
Kini anda boleh beri ujian anda pangkalan data pakai buang.
You finished this before. Practice is always welcome!
Official docs: About service containers · Creating PostgreSQL service containers
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?