C++ Docker remote API client

I’ve built a block to control Docker daemon from C++ source code. It’s available here: lasote/docker_client

biicode-cplus-docker

What’s Docker


Docker
is an open platform for developers and sysadmins to build, ship, and run distributed applications. Consisting of Docker Engine, a portable, lightweight runtime and packaging tool, and Docker Hub, a cloud service for sharing applications and automating workflows, Docker enables apps to be quickly assembled from components and eliminates the friction between development, QA, and production environments. As a result, IT can ship faster and run the same app, unchanged, on laptops, data center VMs, and any cloud.

What’s Docker remote API?

Docker also exposes a REST API to control your docker service. This API is at least as powerfull as the Docker client.

Why would I need a C++ Docker client for Docker’s remote API?

Because you can fully control Docker daemon from your C++ source code!
For example, you may want to automate the creation of some images, or run some linux instances on demand to build your software, maybe build a CI platform…

Brief comments about lasote/docker_client

  • It’s the very first docker client for C++ language.
  • Multiplatform, tested on Windows with Visual Studio and MinGW, Linux with GCC and MacOSx with Clang.
  • It’s based on libuv library for event driven networking.
  • Modern C++11 style.

Want to try it?

Get started with biicode.

Create a new biicode project and a new block

Enable TCP access for your docker instance

You can follow this tutorial to enable TCP access for your docker instance.

Create a main.cpp and paste this example code

NOTE: In this example I used lambda functions, but if you prefer the “classic code” you can pass any “function” object to success callback and error callback.

Paste in myproject/blocks/myuser/myblock/main.cpp:

Just build it!

TODO

– This library implements about a 70% of docker v1.16 interface. Most important methods are already implemented.
– Libuv doesn’t support SSL/TLS so, it does not support HTTPs yet. You can replace Libuv easily replaced and use any other network framework to support it. It does not support unix socket for the same reason.

All github pull request are welcome, so please contribute! See the issues on GitHub for work to be done.

Hope you enjoy this new feature and, as always, we look forward to read what you think. Just click on the sidebar button to try biicode, check our docs, forum and/or Stackoverflow tag for questions and answers.


Related Posts