Using modules for Testcontainers with Golang
Testcontainers for Go lets integration tests start real dependencies such as Redis in containers, but raw usage requires knowing ports, wait strategies and environment details. Zalando built an internal wrapper library using the Functional Options Pattern to supply per-dependency defaults, then migrated to the official Testcontainers modules, which do the same job and cut maintenance. A common problem is the Ryuk garbage-collector sidecar failing under Podman; it can be fixed by disabling it with TESTCONTAINERS_RYUK_DISABLED or by running Podman rootful with the privileged and Docker socket override variables.
Related posts
- GoFiber v3 + Testcontainers: Production-like Local Dev with Air
Docker mediumAdeptFiber v3's new Services API lets a Go web app start and stop backing dependencies as part of its own lifecycle, and a Testcontainers contrib module plugs real Docker containers into it. A todo app walkthrough uses Go build tags to keep a production config that reads the database URL from the environment, alongside a dev config that launches PostgreSQL 16 via testcontainers-go and reads the connection string from app state. It also sets startup and shutdown context providers with timeouts, and uses air for hot reload. Disabling Ryuk and reusing containers by name keeps the database alive across reloads for a fast inner loop.
- Functional tests with Testcontainers
Zalando Engineering mediumAdeptBlack-box functional tests for a Spring service can run against the service packaged as a Docker image, with PostgreSQL and other dependencies started as separate containers via Testcontainers. The setup uses a Maven multi-module layout where the functional-tests module has no dependency on service code. Tests talk to the service only through plain JSON over its public REST API, and a shared abstract base class starts containers once with health-check waits, log consumers, a remote debug port and a shutdown hook as a backstop to Ryuk. The approach gives strong confidence during deep refactoring and also verifies the Docker packaging. Its costs are slow container startup (about 4s for Postgres, up to 20s for Localstack), harder debugging, and the need to isolate test data because containers are shared across tests.
- Shift-Left Testing with Testcontainers: Catching Bugs Early with Local Integration Tests
Docker mediumAdeptRunning integration tests locally against real dependencies via Testcontainers catches bugs that unit tests and mocks miss, before code reaches shared CI or staging environments. A worked TypeScript example shows a user-registration service that allows duplicate emails differing only in case, then compares four ways to catch it. Unit tests miss it, E2E tests catch it too late, mocks must duplicate the validation logic, and a PostgreSQL container test catches it in seconds. The post also estimates DORA-metric gains for the shift-left workflow, such as under 20 minutes versus roughly 2 hours to find and fix a bug, and pitches Testcontainers Cloud for CI and team-scale use.
- Why Testcontainers Cloud Is a Game-Changer Compared to Docker-in-Docker for Testing Scenarios
Docker mediumAdeptDocker-in-Docker, commonly used to give CI jobs a Docker daemon for Testcontainers integration tests, requires privileged mode and nests storage drivers, cgroups and namespaces, which leads to security audit problems, flaky builds, slow pipelines and hard debugging. Testcontainers Cloud offloads container execution to a cloud service through an agent, removing the need for privileged containers or a local Docker socket. Setup in GitHub Actions takes a service-account token stored as TC_CLOUD_TOKEN and the atomicjar/testcontainers-cloud-setup-action step before running tests. The claimed gains in build speed and maintenance are anecdotal and not quantified.
- Streamlining Local Development with Dev Containers and Testcontainers Cloud
Docker mediumAdeptTestcontainers-based tests and services can run inside a dev container by giving the container Docker access, either through the Docker-in-Docker feature or by swapping in the Testcontainers Cloud feature, which runs an agent that points Docker calls at a remote cloud environment. A walkthrough using IntelliJ's Dev Containers plugin and a Spring Boot Java 21 workshop repo shows both devcontainer.json configurations. The Testcontainers Cloud setup passes a TC_CLOUD_TOKEN via an env file kept out of git, sets TCC_PROJECT_KEY to group sessions, and is checked through the agent log. Moving to Testcontainers Cloud is pitched as avoiding Docker-in-Docker's security concerns and local resource load.