How to Provide a Redis Fixture With Compose in CI
A Redis service in Compose gives cache and queue tests a real backend, with a redis-cli ping healthcheck so tests wait for it.
Define a redis service, publish port 6379, and add a redis-cli ping healthcheck so CI blocks until Redis answers before tests connect.
Steps
- Use the official
redisimage. - Add a
redis-cli pinghealthcheck. - Connect from tests via
redis://localhost:6379.
Compose file
docker-compose.yml
services:
redis:
image: redis:7-alpine
ports: ["6379:6379"]
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10Gotchas
- By default this Redis is not persistent; that is usually what you want for isolated CI tests.
- If you enable auth, the ping healthcheck must pass the password or it reports unhealthy.
Related guides
How to Provide a Postgres Fixture With Compose in CIStand up a disposable Postgres for CI tests with docker compose, seed it via an init script, and gate the tes…
How to Provide a MySQL Fixture With Compose in CISpin up a throwaway MySQL for CI tests with docker compose, gate the suite on a mysqladmin ping healthcheck,…
How to Add Compose Healthchecks and Gate CI on ThemDefine healthcheck blocks in docker-compose.yml with test, interval, and retries so docker compose up --wait…