GithubHelp home page GithubHelp logo

libdocker's Introduction

libdocker: an SDK for the Docker Engine API in C

A minimalist SDK for accessing the Docker Engine API via C.

Getting started

libdocker depends on curl, which can be installed easily via most package managers or from source. A typical workflow:

  • docker_init initializes a UNIX socket connection to the Docker Engine
  • docker_post and docker_get send requests to the Docker Engine REST API
  • docker_buffer gets response data
  • docker_destroy destroys docker object and frees any associated memory

The library is pretty low-level for now (i.e., doesn't support parsing JSON responses or have any functions higher-level than post or get). An example application:

#include "docker.h"

int main() {

  fprintf(stderr, "curl_version: %s\n", curl_version());

  DOCKER *docker = docker_init("v1.25");

  if (docker) {
    CURLcode response = docker_post(docker, "http://v1.25/containers/create",
                                    "{\"Image\": \"alpine\", \"Cmd\": [\"echo\", \"hello world\"]}");
    if (response == CURLE_OK) {
      fprintf(stderr, "%s\n", docker_buffer(docker));
    }

    response = docker_get(docker, "http://v1.25/images/json");

    if (response == CURLE_OK) {
      fprintf(stderr, "%s\n", docker_buffer(docker));
    }

    docker_destroy(docker);
  } else {
    fprintf(stderr, "ERROR: Failed to get get a docker client!\n");
  }

  return 0;
}

Adding as CMake subdirectory dependency

Add the following lines to your CMakeLists.txt.

# Let's say the libdocker directory is lib/libdocker
set(LIBDOCKER_DIR lib/libdocker)

# Add subdirectory to compile the static library
add_subdirectory(${LIBDOCKER_DIR})

# Make sure CMake knows where the header files are
target_include_directories(
    ${PROJECT_NAME} PUBLIC
    ${CMAKE_CURRENT_LIST_DIR}/${LIBDOCKER_DIR}/${DOCKER_INCLUDE_DIR}
)

# Link in the static library
target_link_libraries(
    ${PROJECT_NAME}
    docker
)

Multi-threaded applications

Should be fine, but be sure to have a look at curl's page on the subject (link here).

libdocker's People

Contributors

danielsuo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.