Video in progress

Staff 🧪 Testing

What infrastructure problems does using Testcontainers in CI cause, and how do you solve them at the organization level?

CI runners need access to Docker (Docker-in-Docker or a socket mount, and both have a security cost), pulling images every time is slow and hits the Docker Hub limit, and parallel jobs compete for resources. The solution is an internal registry mirror, pre-warmed images, and a remote container runtime if needed.

📖 Answer

On a local machine Testcontainers "just works". In CI, several problems come up:

Access to Docker. Kubernetes-based runners have no Docker daemon. The options: a privileged DinD sidecar (the security team is usually against it), mounting the host socket (opens a path from the container to the host), rootless Docker or Podman, or a service that runs the containers in a remote environment (for example, Testcontainers Cloud). This is a trade-off between security and cost, and I decide it together with the security team.

Pulling images. Every job pulls postgres:16, kafka, redis, each hundreds of MB. Docker Hub's anonymous limit, a slow network. The fix: an internal registry mirror (Harbor, Artifactory, Nexus) and automatically rewriting image names with hub.image.name.prefix in testcontainers.properties. Preload the frequently used images into the runner image.

Version discipline. A test that uses postgres:latest gives a different result one day. In the organization's template, use exact tags, and have Renovate/Dependabot update them.

Resources. With 8 parallel jobs, each with Postgres + Kafka, the runner node runs out of memory, and an OOM kill makes the test look "flaky". Memory limits on containers, explicit resource requests for runners.

Ryuk. Testcontainers' cleanup container; in some environments it can't run and gets turned off (TESTCONTAINERS_RYUK_DISABLED=true). Then cleaning up the containers after the job becomes the runner's responsibility. Don't forget this, otherwise the nodes fill up with leftover containers.

The platform team provides the common settings in one place (runner image + template), so each service team doesn't rediscover this.