I am proud to announce my latest work: Docker.DotNet. It is a .NET library to interact with Docker API programmatically in C#/VB.NET applications. Using this library, you can command your docker instance to pull images, create containers, stop containers and many other things available in the Docker Remote API.

The story behind it is, Docker has almost no tooling on Windows at the moment and I wanted to enable developers who would like to write Docker management apps for Windows on top of Docker API. This library will easily enable to develop such applications without managing with details and mess of Docker Remote API, you can just focus on your application’s core functionality and value add.

The library is designed to be fully asynchronous, meaning there are no blocking calls in networking and streaming functionality. This will play well with your .NET 4.5+ applications. The library is also an object oriented model to interact with the API.

All the parameters to the API endopoints are defined as separate classes and responses are also usually classes. This enables us to maintain this library over time without breaking your code. The v1.0 is out on NuGet package manager, you can quickly get it for your project and continue developing on top of Docker API. (Don’t forget to star on GitHub!)

Getting started

DockerClient client = new DockerClientConfiguration("tcp://your-docker-host:4243").CreateClient();

That literally couldn’t get any easier! :-) If you need to authenticate using SSL/TLS certificates, it does not get any more difficult:

var certificate = new X509Certificate2 ("CertFile", "Password");
var credentials = new CertificateCredentials(certificate);
DockerClient client = new DockerClientConfiguration("tcp://your-docker-host:4243", credentials).CreateClient();

Play with it

The code below starts an existing Docker container with specified host configuration. Below, we configure our container to use Google DNS and just start it!

await client.Containers.StartContainerAsync ("39e3317fd258", new HostConfig(){
    Dns = new[]{"8.8.8.8", "8.8.4.4"}
});

If you’d like to stop the container it’s as easy as:

var stopped = await client.Containers.StopContainerAsync ("39e3317fd258",
    new StopContainerParameters(){
        Wait = TimeSpan.FromSeconds(30)
    },
    CancellationToken.None);

Conclusion

As you see, it could not get any easier to develop applications using Docker API on C#/VB.NET. If you like it please try to develop application on top (and let me know how you liked it, I appreciate your feedback!) and star on GitHub!

The code is open sourced under Apache 2.0 License and can be found on GitHub. You’re more than welcomed to contribute and I’d love to discuss possibilities you can create with this library. If you’re interested to do more stuff about Docker on Windows, please hit me up on email or twitter!

(If you are interested check out My Docker and Linux Containers talk at Microsoft

*(Photo credit: D Ramey Logan, CC BY-SA 3.0)*