miguelcouteirorodrigues.DockerTools 1.4.1

dotnet add package miguelcouteirorodrigues.DockerTools --version 1.4.1
                    
NuGet\Install-Package miguelcouteirorodrigues.DockerTools -Version 1.4.1
                    
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="miguelcouteirorodrigues.DockerTools" Version="1.4.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="miguelcouteirorodrigues.DockerTools" Version="1.4.1" />
                    
Directory.Packages.props
<PackageReference Include="miguelcouteirorodrigues.DockerTools" />
                    
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 miguelcouteirorodrigues.DockerTools --version 1.4.1
                    
#r "nuget: miguelcouteirorodrigues.DockerTools, 1.4.1"
                    
#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 miguelcouteirorodrigues.DockerTools@1.4.1
                    
#: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=miguelcouteirorodrigues.DockerTools&version=1.4.1
                    
Install as a Cake Addin
#tool nuget:?package=miguelcouteirorodrigues.DockerTools&version=1.4.1
                    
Install as a Cake Tool

DockerTools

DockerTools is a simple wrapper on top of Docker.DotNet.

DockerTools was created as a means of abstracting the complexity of managing database containers when running automated tests. It provides a simple, fluent approach to creating, interacting, and disposing of containers.

How to use

Creating a container

Install the package, then simply perform the following:

var container = await new DockerToolsContainer<Postgres>()
           .CreateAsync();
Tweaking the container

If necessary, certain default values can be replaced by using the WithParameters() method:

var container = await new DockerTools<Postgres>()
           .WithParameters(options => options
               .WithDatabase("MyDatabase")
               .WithUsername("myUser")
               .WithPassword("myPassword")
               .WithTag("14.3"))
           .CreateAsync();

Note that you don't have to call all options; simply use the ones you need.

Additionally, you may also supply environment variables, such as enabling SQL Server Agent on SQL Server:

var container = await new DockerTools<SqlServer>()
           .WithParameters(options => options
               .AddEnvironmentVariable("MSSQL_AGENT_ENABLED=True"))
           .CreateAsync();

(Please consult the image's documentation for supported variables; list of official images can be found at the Supported Databases section.)

Finally, you may use a different image than the officially supported one (not recommended):

var container = await new DockerTools<SqlServer>()
           .WithParameters(options => options
               .WithImage("vibs2006/sql_server_fts")) // adds full text support that the official image lacks
           .CreateAsync();
Connecting to the Docker Engine

By default, DockerTools will attempt to identify the best connection to the local Docker instance. if you want to force use of the Remote API, you can do so:

var container = await new DockerTools<Postgres>()
           .WithConnection(options => options.ConnectionType = new RemoteApiConnection(new Uri("http://localhost:2375")))
           .CreateAsync();

Using the container

You can obtain the container's connection string by checking its ConnectionString property like this:

var connectionString = container.ConnectionString; // returns a string value

Inside the ConnectionString object, you can also directly access the database name, port, username, and password:

var database = container.ConnectionString.Database;
var port = container.ConnectionString.Port;
var username = container.ConnectionString.Username;
var password = container.ConnectionString.Password;

You can also run scripts by calling the following method:

var result = container.RunScriptAsync("SELECT * from users");

The method will return an object indicating if the script ran successfully, with an optional field indicating the error if one exists.

Clean up

When done with the container, simply invoke its DisposeAsync method:

container.DisposeAsync();

This will remove the container from the Docker host and dispose of the underlying connection to it.

Note that the CreateAsync() method generates an IAsyncDisposable object, meaning you can wrap the entire usage of it in an await using statement:

await using (var container = await new DockerTools<Postgres>().CreateAsync())
{
    ...
}

Alternatively, if disposing is not an option, you can initialize the container with the WithCleanUp(true) method:

var container = await new DockerTools<Postgres>()
           .WithCleanUp(true)
           .CreateAsync();

Supported Databases

Container Image Version Notes
Postgres postgres 14.3
Postgis postgis/postgis 14-3.4
SQL Server mcr.microsoft.com/mssql/server 2022-latest
SQL Server (Full Text Search) vibs2006/sql_server_fts 2022 Will be deprecated in a future version in favor of the WithImage() option
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 was computed.  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 was computed.  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. 
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.4.1 370 9/15/2025
1.4.0 157 9/12/2025
1.3.0 180 9/12/2025 1.3.0 is deprecated because it has critical bugs.
1.2.0 213 9/11/2025
1.1.4 164 2/25/2025
1.1.3 178 2/21/2025
1.1.2 166 2/20/2025
1.1.1 169 2/20/2025
1.1.0 163 1/26/2025