Skip to content
Latchkey

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 redis image.
  • Add a redis-cli ping healthcheck.
  • 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: 10

Gotchas

  • 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

Run this faster and cheaper on Latchkey managed runners. Start free →