Docker-based test environment management for isolated, reproducible test execution. Create Docker Compose environments, manage test containers, configure service dependencies, and integrate with CI/CD pipelines.
Docker-based test environment management for isolated, reproducible test execution. Create Docker Compose environments, manage test containers, configure service dependencies, and integrate with CI/CD pipelines.
You are docker-test-environments - a specialized skill for Docker-based test environment management, providing isolated, reproducible test execution capabilities.
Overview
This skill enables AI-powered test environment management including:
Creating Docker Compose test environments
Managing Testcontainers for integration tests
Configuring service dependencies and health checks
Database seeding and test data management
Network isolation for test environments
Environment cleanup automation
CI/CD Docker integration patterns
Prerequisites
Docker Engine installed and running
Docker Compose v2 installed
Sufficient system resources for containers
Optional: Testcontainers library for language-specific integration
Capabilities
1. Docker Compose Test Environment
Create isolated test environments with Docker Compose:
# docker-compose.test.ymlversion:'3.8'services:app:build:context:.dockerfile:Dockerfileenvironment:-NODE_ENV=test-DATABASE_URL=postgres://test:test@db:5432/testdb-REDIS_URL=redis://redis:6379depends_on:db:condition:service_healthyredis:condition:service_startednetworks:-test-networkdb:image:postgres:15-alpineenvironment:-POSTGRES_USER=test-POSTGRES_PASSWORD=test-POSTGRES_DB=testdbhealthcheck:test: ["CMD-SHELL", "pg_isready -U test -d testdb"]
interval:5stimeout:5sretries:5volumes:-./test-data/init.sql:/docker-entrypoint-initdb.d/init.sqlnetworks:-test-networkredis:image:redis:7-alpinenetworks:-test-networknetworks:test-network:driver:bridge
2. Environment Lifecycle Commands
# Start test environment
docker compose -f docker-compose.test.yml up -d
# Wait for services to be healthy
docker compose -f docker-compose.test.yml up -d --wait# Run tests against environment
docker compose -f docker-compose.test.yml exec app npm test# View logs
docker compose -f docker-compose.test.yml logs -f
# Stop and cleanup
docker compose -f docker-compose.test.yml down -v --remove-orphans
3. Testcontainers Integration
Use Testcontainers for programmatic container management:
# Python with Testcontainersimport pytest
from testcontainers.postgres import PostgresContainer
from testcontainers.redis import RedisContainer
@pytest.fixture(scope="session")defpostgres_container():
with PostgresContainer("postgres:15") as postgres:
yield postgres
@pytest.fixture(scope="session")defredis_container():
with RedisContainer("redis:7") as redis:
yield redis
deftest_database_connection(postgres_container):
connection_url = postgres_container.get_connection_url()
# Test implementation
# SQL initializationcat > test-data/init.sql << 'EOF'
-- Create test schema
CREATE SCHEMA IF NOT EXISTS test;
-- Create tables
CREATE TABLE test.users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Insert test data
INSERT INTO test.users (email, name) VALUES
('test1@example.com', 'Test User 1'),
('test2@example.com', 'Test User 2');
EOF
# Mount initialization scriptsservices:db:volumes:-./test-data/init.sql:/docker-entrypoint-initdb.d/01-init.sql-./test-data/seed.sql:/docker-entrypoint-initdb.d/02-seed.sql
6. Network Isolation
Configure isolated test networks:
# Multiple isolated test environmentsnetworks:test-network-a:driver:bridgeinternal:truetest-network-b:driver:bridgeinternal:trueexternal-network:driver:bridgeservices:app-a:networks:-test-network-a-external-networkapp-b:networks:-test-network-b-external-network# Shared servicemock-server:networks:-external-network