GitLab CI/CD `services:` & Docker-in-Docker Integration Testing Prompt
Stand up databases, brokers, and dependent containers as CI `services:` (or via DinD) for integration tests — health-gating, aliases, networking, and isolation per job.
- Target user
- Engineers running integration/E2E tests against real dependencies in CI
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior CI engineer who runs reliable integration tests against real Postgres, Redis, Kafka, and app containers in GitLab jobs without flaky "connection refused" races. I will provide: - The dependencies my tests need (DB, cache, queue, mock APIs, the app under test) - My test command and language - Runner executor (Docker, Kubernetes, shell) and whether privileged mode is allowed - Current flakiness or networking errors Your job: 1. **Choose `services:` vs Docker-in-Docker** — `services:` for "I need N sidecar containers reachable by alias" (simplest, no privileged needed); DinD/`docker:dind` only when tests must BUILD images or run `docker compose`/Testcontainers. Recommend one and justify. 2. **Wire `services:` correctly** — show the `services:` block with `name`, `alias`, and command/entrypoint overrides; explain how the job container reaches a service by its alias hostname (e.g. `postgres:5432`), and that `localhost` does NOT work on the Docker executor. 3. **Gate on readiness** — services start in parallel with the job, so add a wait loop (`pg_isready`/`redis-cli ping`/`nc -z`) in `before_script` instead of `sleep`; provide the snippet. This kills most flakiness. 4. **Configure DinD safely** — if needed: `docker:dind` service, `DOCKER_HOST=tcp://docker:2376`, TLS vars, privileged runner caveat, and prefer Testcontainers' `TC_HOST`/DinD networking or `DOCKER_TLS_CERTDIR`. Note the security cost of privileged. 4. **Isolate per job** — unique DB names/schemas per `CI_JOB_ID` so parallel jobs don't share state; ephemeral data, no cleanup needed since the container dies with the job. 5. **Pass credentials** — service env vars (`POSTGRES_PASSWORD`, etc.) via `variables:`, and how the test app reads matching connection vars. 6. **Debug** — how to see service logs (they're folded into the job log), diagnose image pull/auth issues, and cache base images. 7. **Validate** — run the job 10x and confirm zero connection-refused flakes; confirm tests actually hit the real service (not a mock). Output: (a) the job with `services:` (or DinD) configured, (b) the readiness wait `before_script`, (c) per-job isolation setup, (d) connection variables, (e) a flakiness/debug checklist. Bias toward: `services:` over DinD when possible, readiness gates over sleeps, and least-privilege (avoid privileged unless building images).
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
GitLab CI/CD k6 Load Test Performance Gate Prompt
Design a .gitlab-ci.yml stage that runs k6 load/performance tests against a review or staging environment, enforces threshold-based pass/fail gates, and surfaces results as artifacts and metrics reports in merge requests.
-
GitLab CI/CD Publish to the Package Registry (npm, Maven, generic) Prompt
Design .gitlab-ci.yml jobs that build and publish versioned artifacts to the project or group Package Registry using CI_JOB_TOKEN auth, with proper version gating, immutability, and consumer install config.
-
GitLab CI/CD Windows Runner & PowerShell Pipeline Prompt
Design .gitlab-ci.yml pipelines that run on Windows runners (shell or docker-windows executor) with correct PowerShell shell handling, tag targeting, path/quoting fixes, and mixed Linux/Windows stages.
-
GitLab CI/CD allow_failure:exit_codes Soft-Gate Prompt
Use allow_failure:exit_codes to turn specific job exit codes into non-blocking warnings while keeping real failures red — soft gates for advisory linters, optional checks, and known-flaky tooling.
More GitLab CI/CD prompts & error guides
Browse every GitLab CI/CD prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.