MiniStack.Testcontainers 1.1.0

dotnet add package MiniStack.Testcontainers --version 1.1.0
                    
NuGet\Install-Package MiniStack.Testcontainers -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MiniStack.Testcontainers" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MiniStack.Testcontainers" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="MiniStack.Testcontainers" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MiniStack.Testcontainers --version 1.1.0
                    
#r "nuget: MiniStack.Testcontainers, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MiniStack.Testcontainers@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MiniStack.Testcontainers&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=MiniStack.Testcontainers&version=1.1.0
                    
Install as a Cake Tool

MiniStack.Testcontainers

A Testcontainers for .NET module for MiniStack, a free, open-source AWS emulator that serves its AWS services on a single port (4566).

This is a community package. It is not affiliated with or maintained by the Testcontainers project or by MiniStack. It started as testcontainers/testcontainers-dotnet#1806.

Install

dotnet add package MiniStack.Testcontainers

The package targets net8.0, net9.0, net10.0, netstandard2.0 and netstandard2.1, and depends on the Testcontainers package. The types live in the Testcontainers.MiniStack namespace.

Usage

using Testcontainers.MiniStack;

var miniStackContainer = new MiniStackBuilder("ministackorg/ministack:1.5.31")
    .Build();

await miniStackContainer.StartAsync();

var config = new AmazonS3Config
{
    ServiceURL = miniStackContainer.GetConnectionString(),
    AuthenticationRegion = miniStackContainer.GetRegion(),
    ForcePathStyle = true,
};

var credentials = new BasicAWSCredentials(miniStackContainer.GetAccessKey(), miniStackContainer.GetSecretKey());

using var client = new AmazonS3Client(credentials, config);

Use GetConnectionString() as the AWS SDK ServiceURL, and GetRegion(), GetAccessKey() and GetSecretKey() for the region and credentials. By default, MiniStack uses the region us-east-1 and the credentials test/test.

The container is ready once /_ministack/health returns HTTP 200 and then /_ministack/ready returns HTTP 200, which happens after all ready scripts have run.

Configuration

The builder sets MiniStack's environment variables for the most common options:

var miniStackContainer = new MiniStackBuilder("ministackorg/ministack:1.5.31")
    .WithRegion("eu-west-1")
    .WithCredentials("123456789012", "secret")
    .WithPersistence()
    .WithImdsV2Required()
    .Build();
  • WithRegion(string) sets MINISTACK_REGION, the region MiniStack uses in the ARNs it generates.
  • WithCredentials(string, string) sets AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. MiniStack treats a 12-digit access key as the account ID.
  • WithPersistence() sets PERSIST_STATE=1 and S3_PERSIST=1, so service state and S3 objects are written to disk and survive a restart of the same container.
  • WithImdsV2Required() sets MINISTACK_IMDS_V2_REQUIRED=1, so instance metadata requests without a session token are rejected.
  • WithServices(params string[]) sets SERVICES, so MiniStack loads only the listed services, e.g. WithServices("s3", "sqs").
  • WithMemoryLimit(long) limits the MiniStack container's memory, in bytes. See Memory limit.

GetMiniStackVersion() returns the image tag, or null for an image referenced only by digest. GetMiniStackVersionAsync() returns the version the running server reports, which also resolves tags such as latest.

Memory limit

By default, the MiniStack container has no memory limit, so a runaway MiniStack can use up the memory of the Docker host, or of the VM that runs Docker on macOS and Windows. WithMemoryLimit(long) sets a limit in bytes:

var miniStackContainer = new MiniStackBuilder("ministackorg/ministack:1.5.31")
    .WithMemoryLimit(4L * 1024 * 1024 * 1024)
    .Build();

It sets HostConfig.Memory and HostConfig.MemorySwap to the same value, so the container gets no swap on top of the limit. The value must be greater than zero. The limit applies to the MiniStack container only, not to the containers it starts for real infrastructure.

If the container is OOM-killed before it is ready, StartAsync throws an InvalidOperationException with a message such as MiniStack was OOM-killed (memory limit 4 GiB)., instead of a wait strategy timeout or a bare exit code 137.

If Testcontainers is configured with a hub image name prefix, the module passes it to MiniStack as MINISTACK_IMAGE_PREFIX, so the images MiniStack pulls for real infrastructure come from the same registry.

Init and ready scripts

MiniStack runs shell (.sh) and Python (.py) scripts in alphabetical order of their file names. Use WithInitScript(string) or WithInitScriptContent(string, string) for boot scripts, which run before MiniStack serves requests. Use WithReadyScript(string) or WithReadyScriptContent(string, string) for ready scripts, which run once MiniStack serves requests and can create AWS resources:

var miniStackContainer = new MiniStackBuilder("ministackorg/ministack:1.5.31")
    .WithInitScriptContent("01-boot.sh", "echo booted > /tmp/booted")
    .WithReadyScriptContent("01-create-bucket.sh", "aws s3 mb s3://seeded-bucket")
    .WithReadyScript("02-create-queue.py")
    .Build();

The ready scripts can use the AWS CLI (aws, awslocal) and boto3, which MiniStack preconfigures with its endpoint, region and credentials. If a ready script fails, StartAsync throws an InvalidOperationException, and the script output is in the container logs.

Older MiniStack images have no /_ministack/ready endpoint and return HTTP 404. For those, the container is ready once /_ministack/health returns HTTP 200, the module does not wait for ready scripts, and it cannot detect a failed one.

Real infrastructure

WithRealInfrastructure() bind-mounts the Docker socket into the container. It uses the same socket path as the Resource Reaper, including the TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE setting. MiniStack then runs real containers for services such as RDS, ElastiCache, ECS and Lambda:

var miniStackContainer = new MiniStackBuilder("ministackorg/ministack:1.5.31")
    .WithRealInfrastructure()
    .WithRdsPublicEndpoint()
    .Build();

By default, RDS reports the database container's address on the Docker network, which a test running on a macOS or Windows host cannot reach. WithRdsPublicEndpoint() sets MINISTACK_RDS_PUBLIC_ENDPOINT=1, so RDS reports localhost and the published host port instead. That address works when the tests and the Docker daemon run on the same machine.

Anything running inside MiniStack, including the code of a Lambda function, gets full control over the host's container engine. Use real infrastructure only on trusted machines and CI runners.

A long-running MiniStack with real infrastructure can grow large. Consider a memory limit, so that MiniStack is OOM-killed on its own instead of taking the Docker host or VM down with it.

The Resource Reaper does not know about the containers MiniStack starts. When MiniStack is stopped, it removes them itself. Disposing the container kills MiniStack before it can do that, so the module then removes the containers and volumes that carry its ministack.instance label. MiniStack builds that label from MINISTACK_HOSTNAME (or the container hostname) and the gateway port. Containers of another MiniStack instance on the same Docker daemon are left alone, unless both instances set the same MINISTACK_HOSTNAME and port.

If the test host is killed, the module cannot clean up. The Resource Reaper still removes the MiniStack container, but the containers MiniStack started keep running. So when a container with real infrastructure starts, the module first removes the containers and volumes whose ministack.instance label is <host>:<port>, where <host> is a 12-character container id (the default container hostname) and no container with that id exists any more. A MiniStack container that is stopped but not removed still counts as existing. Labels whose host is not a container id, such as those of a MiniStack running directly on the host machine or one with MINISTACK_HOSTNAME set to a name, are never touched. Resources created in the last two minutes are skipped, so a MiniStack that is still starting is not raced. The sweep is best-effort and bounded by a one-minute timeout: failures are logged, and the start goes on. To turn it off, use WithOrphanSweep(false).

Build and test

dotnet build -c Release
dotnet test -c Release

The tests start real MiniStack containers, so they need a running Docker daemon. The MiniStack image the tests use is pinned in tests/Testcontainers.MiniStack.Tests/Dockerfile.

Releasing

Push a tag v<version>, e.g. v1.0.1. The release workflow builds, tests, packs with that version and pushes to nuget.org through trusted publishing (a nuget.org policy for this repo and release.yml).

License

MIT. The test helpers TestSession and DockerfileParser are copied from Testcontainers for .NET, also MIT.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 89 11/3/2026
1.0.0 89 11/2/2026