Skip to main content
New to Testkube? Unleash the power of cloud native testing in Kubernetes with Testkube. Get Started >

Using TestContainers with Testkube

info

This Workflows functionality is not available when running the Testkube Agent in Standalone Mode - Read More

TestContainers is a popular framework for managing test dependencies on specific Docker containers.

To make sure TestContainers can successfully launch defined Docker images, it is recommended to define a separate service in your Workflow that runs a docker-in-docker (dind) image, which can then be used by TestContainers by overriding the DOCKER_HOST environment variable in your test executions.

The below example runs an Ollama Hugging Face example test from the testcontainers-java repository that uses TestContainers to spawn corresponding Ollama dependencies

  • The spec.content property defines the location of the GitHub project
  • The spec.services.dind property starts the Docker-in-Docker container (read more about Services)
  • the spec.steps property defines a single step that runs the Ollama test with gradle, overriding the DOCKER_HOST environment variable with the internal service ip of the dind service.
Ollama HuggingFace test with Gradle and TestContainers Workflow
kind: TestWorkflow
apiVersion: testworkflows.testkube.io/v1
metadata:
name: gradle-with-testcontainers
namespace: testkube
spec:
content:
git:
uri: https://github.com/testcontainers/testcontainers-java
revision: main
container:
workingDir: /data/repo/examples/ollama-hugging-face
resources:
requests:
cpu: 512m
memory: 512Mi
services:
dind:
logs: always
timeout: 5m
image: docker:27.4.0-dind
env:
- name: DOCKER_TLS_CERTDIR
securityContext:
privileged: true
readinessProbe:
tcpSocket:
port: 2375
steps:
- name: Run tests
run:
image: gradle:8.5.0-jdk11
env:
- name: TESTKUBE_GRADLE
value: "true"
- name: DOCKER_HOST
value: tcp://{{ services.dind.0.ip }}:2375
command:
- gradle
- --no-daemon
- test
artifacts:
paths:
- reports/**/*
- test-results/**/*

After execution, you can see the output from the test executions under the executions panel tabs:

The log output from the test execution:

Ollama TestContainers Log Output