MiniStack.Testcontainers
1.0.0
See the version list below for details.
dotnet add package MiniStack.Testcontainers --version 1.0.0
NuGet\Install-Package MiniStack.Testcontainers -Version 1.0.0
<PackageReference Include="MiniStack.Testcontainers" Version="1.0.0" />
<PackageVersion Include="MiniStack.Testcontainers" Version="1.0.0" />
<PackageReference Include="MiniStack.Testcontainers" />
paket add MiniStack.Testcontainers --version 1.0.0
#r "nuget: MiniStack.Testcontainers, 1.0.0"
#:package MiniStack.Testcontainers@1.0.0
#addin nuget:?package=MiniStack.Testcontainers&version=1.0.0
#tool nuget:?package=MiniStack.Testcontainers&version=1.0.0
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)setsMINISTACK_REGION, the region MiniStack uses in the ARNs it generates.WithCredentials(string, string)setsAWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY. MiniStack treats a 12-digit access key as the account ID.WithPersistence()setsPERSIST_STATE=1andS3_PERSIST=1, so service state and S3 objects are written to disk and survive a restart of the same container.WithImdsV2Required()setsMINISTACK_IMDS_V2_REQUIRED=1, so instance metadata requests without a session token are rejected.WithServices(params string[])setsSERVICES, so MiniStack loads only the listed services, e.g.WithServices("s3", "sqs").
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.
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.
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.
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 | Versions 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. |
-
.NETStandard 2.0
- Testcontainers (>= 4.16.0)
-
.NETStandard 2.1
- Testcontainers (>= 4.16.0)
-
net10.0
- Testcontainers (>= 4.16.0)
-
net8.0
- Testcontainers (>= 4.16.0)
-
net9.0
- Testcontainers (>= 4.16.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.