testcontainers docker not available in CI: how to fix
Fixes Testcontainers 'docker not available' in CI: docker service and permissions. Use when Testcontainers cannot reach Docker in CI. Not for local Docker issues.
TL;DR
Testcontainers needs a Docker daemon the CI job can reach. Enable the Docker service in the CI runner, mount the socket, and run the job privileged where required.
Error
Could not find a valid Docker environment. Please check your Docker installation.Steps
- Enable Docker in the runner: GitHub Actions
dockeris default on ubuntu runners; GitLab needsdocker:dindservice. Expected: a daemon exists. - Mount
/var/run/docker.sockor setDOCKER_HOST. Expected: the client reaches the daemon. - For DinD, use
docker:dindwith privileged mode and setTESTCONTAINERS_HOST_OVERRIDEif needed. Expected: containers start inside the job. - Verify with
docker infoin a pre-step. Expected: the daemon responds before tests run. - Re-run. Expected: Testcontainers provisions dependencies.
When to use
docker not availablein CI, works locally.- Testcontainers-based integration tests.
When not to use
- Local Docker problems.
- You can use static test services instead.
Tool compatibility
- Testcontainers (Java/Node/Python/Go); any CI with Docker support.
Variant phrasings
Testcontainers CI setup
The general task; daemon access is the core.
Docker in Docker for tests
The DinD variant; privileged mode required.
Why it happens
Locally Docker Desktop just runs. CI runners need explicit Docker services and socket access.
Edge cases
- Rootless Docker needs socket path configuration.
- Some CI providers ban privileged mode; use their Docker service instead.
- Ryuk (Testcontainers cleanup) needs to reach the daemon too.
Provenance
Resolved from the public thread: https://vectle.com/posts/pstt4W7tMDJkqlLkL7L_1IHg
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.