![]() |
VOOZH | about |
dotnet add package Docker.DotNet --version 3.125.15
NuGet\Install-Package Docker.DotNet -Version 3.125.15
<PackageReference Include="Docker.DotNet" Version="3.125.15" />
<PackageVersion Include="Docker.DotNet" Version="3.125.15" />Directory.Packages.props
<PackageReference Include="Docker.DotNet" />Project file
paket add Docker.DotNet --version 3.125.15
#r "nuget: Docker.DotNet, 3.125.15"
#:package Docker.DotNet@3.125.15
#addin nuget:?package=Docker.DotNet&version=3.125.15Install as a Cake Addin
#tool nuget:?package=Docker.DotNet&version=3.125.15Install as a Cake Tool
This library allows you to interact with Docker Remote API endpoints in your .NET applications.
It is fully asynchronous, designed to be non-blocking and object-oriented way to interact with your Docker daemon programmatically.
Version of this package uses SemVer format: MAJOR.MINOR.PATCH. MINOR segment indicates
the Docker Remote API version support. For instance v2.124.0 of this library supports
Docker Remote API v1.24. This does not guarantee backwards compatibility as Docker Remote API does not guarantee that either.
MAJOR is reserved for major breaking changes we make to the library itself such as how
the calls are made or how authentication is made. PATCH is just for incremental bug fixes
or non-breaking feature additions.
You can add this library to your project using NuGet.
Package Manager Console Run the following command in the “Package Manager Console”:
PM> Install-Package Docker.DotNet
Visual Studio Right click to your project in Visual Studio, choose “Manage NuGet Packages” and search for ‘Docker.DotNet’ and click ‘Install’. (see NuGet Gallery.)
.NET Core Command Line Interface Run the following command from your favorite shell or terminal:
dotnet add package Docker.DotNet
Development Builds
👁 alternate text is missing from this package README image
If you intend to use development builds of Docker.DotNet and don't want to compile the code yourself you can add the package source below to Visual Studio or your Nuget.Config.
You can initialize the client like the following:
using Docker.DotNet;
DockerClient client = new DockerClientConfiguration(
new Uri("http://ubuntu-docker.cloudapp.net:4243"))
.CreateClient();
or to connect to your local Docker for Windows daemon using named pipes or your local Docker for Mac daemon using Unix sockets:
using Docker.DotNet;
DockerClient client = new DockerClientConfiguration()
.CreateClient();
For a custom endpoint, you can also pass a named pipe or a Unix socket to the DockerClientConfiguration constructor. For example:
// Default Docker Engine on Windows
using Docker.DotNet;
DockerClient client = new DockerClientConfiguration(
new Uri("npipe://./pipe/docker_engine"))
.CreateClient();
// Default Docker Engine on Linux
using Docker.DotNet;
DockerClient client = new DockerClientConfiguration(
new Uri("unix:///var/run/docker.sock"))
.CreateClient();
IList<ContainerListResponse> containers = await client.Containers.ListContainersAsync(
new ContainersListParameters(){
Limit = 10,
});
The code below pulls fedora/memcached image to your Docker instance using your Docker Hub account. You can
anonymously download the image as well by passing null instead of AuthConfig object:
await client.Images.CreateImageAsync(
new ImagesCreateParameters
{
FromImage = "fedora/memcached",
Tag = "alpha",
},
new AuthConfig
{
Email = "test@example.com",
Username = "test",
Password = "pa$$w0rd"
},
new Progress<JSONMessage>());
The following code will create a new container of the previously fetched image.
await client.Containers.CreateContainerAsync(new CreateContainerParameters()
{
Image = "fedora/memcached",
HostConfig = new HostConfig()
{
DNS = new[] { "8.8.8.8", "8.8.4.4" }
}
});
The following code will start the created container.
await client.Containers.StartContainerAsync(
"39e3317fd258",
new ContainerStartParameters()
);
The following code will stop a running container.
Note: WaitBeforeKillSeconds field is of type uint? which means optional. This code will wait 30 seconds before
killing it. If you like to cancel the waiting, you can use the CancellationToken parameter.
var stopped = await client.Containers.StopContainerAsync(
"39e3317fd258",
new ContainerStopParameters
{
WaitBeforeKillSeconds = 30
},
CancellationToken.None);
Some Docker API endpoints are designed to return stream responses. For example Monitoring Docker events continuously streams the status in a format like :
{"status":"create","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
{"status":"start","id":"dfdf82bd3881","from":"base:latest","time":1374067924}
{"status":"stop","id":"dfdf82bd3881","from":"base:latest","time":1374067966}
{"status":"destroy","id":"dfdf82bd3881","from":"base:latest","time":1374067970}
...
To obtain this stream you can use:
CancellationTokenSource cancellation = new CancellationTokenSource();
Stream stream = await client.System.MonitorEventsAsync(new ContainerEventsParameters(), new Progress<JSONMessage>(), cancellation.Token);
// Initialize a StreamReader...
You can cancel streaming using the CancellationToken. On the other hand, if you wish to continuously stream, you can simply pass CancellationToken.None.
If you are running Docker with TLS (HTTPS), you can authenticate to the Docker instance using the Docker.DotNet.X509 package. You can get this package from NuGet or by running the following command in the “Package Manager Console”:
PM> Install-Package Docker.DotNet.X509
Once you add Docker.DotNet.X509 to your project, use CertificateCredentials type:
var credentials = new CertificateCredentials (new X509Certificate2 ("CertFile", "Password"));
var config = new DockerClientConfiguration("http://ubuntu-docker.cloudapp.net:4243", credentials);
DockerClient client = config.CreateClient();
If you don't want to authenticate you can omit the credentials parameter, which defaults to an AnonymousCredentials instance.
The CertFile in the example above should be a .pfx file (PKCS12 format), if you have .pem formatted certificates which Docker normally uses you can either convert it programmatically or use openssl tool to generate a .pfx:
openssl pkcs12 -export -inkey key.pem -in cert.pem -out key.pfx
(Here, your private key is key.pem, public key is cert.pem and output file is named key.pfx.) This will prompt a password for PFX file and then you can use this PFX file on Windows. If the certificate is self-signed, your application may reject the server certificate, in this case you might want to disable server certificate validation:
//
// There are two options to do this.
//
// You can do this globally for all certificates:
ServicePointManager.ServerCertificateValidationCallback += (o, c, ch, er) => true;
// Or you can do this on a credential by credential basis:
var creds = new CertificateCredentials(...);
creds.ServerCertificateValidationCallback += (o, c, ch, er) => true;
If the Docker instance is secured with Basic HTTP Authentication, you can use the Docker.DotNet.BasicAuth package. Get this package from NuGet or by running the following command in the “Package Manager Console”:
PM> Install-Package Docker.DotNet.BasicAuth
Once you added Docker.DotNet.BasicAuth to your project, use BasicAuthCredentials type:
var credentials = new BasicAuthCredentials ("YOUR_USERNAME", "YOUR_PASSWORD");
var config = new DockerClientConfiguration("tcp://ubuntu-docker.cloudapp.net:4243", credentials);
DockerClient client = config.CreateClient();
BasicAuthCredentials also accepts SecureString for username and password arguments.
By default this client does not specify version number to the API for the requests it makes. However, if you would like to make use of versioning feature of Docker Remote API You can initialize the client like the following.
var config = new DockerClientConfiguration(...);
DockerClient client = config.CreateClient(new Version(1, 16));
Here are typical exceptions thrown from the client library:
DockerApiException is thrown when Docker API responds with a non-success result. Subclasses:
DockerContainerNotFoundExceptionDockerImageNotFoundExceptionTaskCanceledException is thrown from System.Net.Http.HttpClient library by design. It is not a friendly exception, but it indicates your request has timed out. (default request timeout is 100 seconds.)
WaitContainerAsync, StopContainerAsync) and methods that return Stream (e.g. CreateImageAsync, GetContainerLogsAsync) have timeout value overridden with infinite timespan by this library.ArgumentNullException is thrown when one of the required parameters are missing/empty.
Docker.DotNet is a .NET Foundation project.
There are many .NET related projects on GitHub.
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information, see the .NET Foundation Code of Conduct.
General .NET OSS discussions: .NET Foundation Discord
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.dotnetfoundation.org.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
Docker.DotNet is licensed under the license.
Copyright (c) .NET Foundation and Contributors
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Docker.DotNet:
| Package | Downloads |
|---|---|
|
Docker.DotNet.X509
Docker.DotNet.X509 is a library that allows you to use certificate authentication with a remote Docker engine programmatically in your .NET applications. |
|
|
DotNet.Testcontainers
A lightweight library to run tests with throwaway instances of Docker containers. |
|
|
Docker.DotNet.BasicAuth
Docker.DotNet.BasicAuth is a library that allows you to use basic authentication with a remote Docker engine programmatically in your .NET applications. |
|
|
TestContainers.Container.Abstractions
DotNet port of testcontainers.org |
|
|
TestEnvironment.Docker
Testing framework for setting up real dependencies as Docker containers. |
Showing the top 20 popular GitHub repositories that depend on Docker.DotNet:
| Repository | Stars |
|---|---|
|
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
|
|
|
danielgerlag/workflow-core
Lightweight workflow engine for .NET Standard
|
|
|
dotnetcore/DotnetSpider
DotnetSpider, a .NET standard web crawling library. It is lightweight, efficient and fast high-level web crawling & scraping framework
|
|
|
EasyNetQ/EasyNetQ
An easy to use .NET API for RabbitMQ
|
|
|
CoreWCF/CoreWCF
Main repository for the Core WCF project
|
|
|
Azure/iotedge
The IoT Edge OSS project
|
|
|
tryAGI/LangChain
C# implementation of LangChain. We try to be as close to the original as possible in terms of abstractions, but are open to new entities.
|
|
|
lecaillon/Evolve
Database migration tool for .NET and .NET Core projects. Inspired by Flyway.
|
|
|
alirezanet/Husky.Net
Lint your commit messages, run tests, format or analyze code, and perform any other checks automatically when you commit or push. 🚀
|
|
|
tomaszzmuda/Xabe.FFmpeg
.NET Standard wrapper for FFmpeg. It allows to process media without know how FFmpeg works, and can be used to pass customized arguments to FFmpeg from dotnet core application.
|
|
|
sdcb/chats
A powerful and flexible frontend & AI gateway for large language models, supporting 21+ mainstream AI model providers.
|
|
|
danielgerlag/conductor
Distributed workflow server
|
|
|
DataDog/dd-trace-dotnet
.NET Client Library for Datadog APM
|
|
|
microsoft/component-detection
Scans your project to determine what components you use
|
|
|
SQLStreamStore/SQLStreamStore
Stream Store library targeting RDBMS based implementations for .NET
|
|
|
rdagumampan/yuniql
Free and open source schema versioning and database migration made natively with .NET/6. NEW THIS MAY 2022! v1.3.15 released!
|
|
|
Azure/azure-libraries-for-net
Azure libraries for .Net
|
|
|
dkorecko/PatchPanda
Self-hostable Docker Compose stack update manager.
|
|
|
serverlessworkflow/synapse
Serverless Workflow Management System (WFMS)
|
|
|
shubhamranjan/dotnet-etcd
A C# .NET (dotnet) GRPC client for etcd v3 +
|
| Version | Downloads | Last Updated |
|---|---|---|
| 3.125.15 | 48,316,876 | 5/18/2023 |
| 3.125.14 | 309,885 | 4/14/2023 |
| 3.125.13 | 1,752,583 | 3/1/2023 |
| 3.125.12 | 4,564,866 | 9/18/2022 |
| 3.125.11 | 102,263 | 9/3/2022 |
| 3.125.10 | 2,169,292 | 7/19/2022 |
| 3.125.5 | 3,430,392 | 8/31/2021 |
| 3.125.4 | 3,834,785 | 8/12/2020 |
| 3.125.2 | 4,561,500 | 4/17/2018 |
| 3.125.1 | 65,767 | 1/31/2018 |
| 3.125.0 | 177,469 | 7/27/2017 |
| 2.124.3 | 113,014 | 10/17/2016 |
| 2.124.1 | 6,355 | 7/15/2016 |
| 1.2.2 | 14,530 | 12/31/2015 |
| 1.2.1 | 4,154 | 11/25/2015 |
| 1.2.0 | 5,544 | 9/17/2015 |
| 1.1.2.1 | 3,678 | 8/21/2015 |
| 1.1.1 | 3,917 | 10/10/2014 |
| 1.1.0 | 5,248 | 9/26/2014 |