Skip to content

mechatheo/DockerClient

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Docker Client

Dependency

Basic Usage

#include "docker.h"
int main(){
    Docker client = Docker();

    JSON_DOCUMENT doc = client.list_containers(true); 
    std::cout << jsonToString(doc) << std::endl;

    return 0;
}

Return of Each Methods

Every return type is JSON_OBJECT (alias of rapidjson::Document)

Refer to RapidJSON for the detailed usage

Object o;
 - success        [bool]                  : if succeeded to request
 - data           [Object/Array/string]   : actual data by server
 - code(optional) [int]                   : http status code if 'success' is false

Data type of 'data' depends on API, but it would be Object if 'success' is false.

e.g.

{
  "success": false,
  "code": 404,
  "data": {
      "message": "No such container: 5d271b3a52263330348b71948bd25cda455a49f7e7d69cfc73e6b2f3b5b41a4c" 
  }
} 
{
  "success": true ,
  "data": {
      "Architecture": "x86_64",
      "SystemTime": "2018-05-23T19:26:54.357768797+09:00" 
 }
}

Accessing Remote Docker Server

For remote access, you sould first bind Docker Server to a port. You can bind by adding -H tcp://0.0.0.0:<port> in service daemon.

# cat /lib/systemd/system/docker.service
....
[Service]
Type=notify
ExecStart=/usr/bin/docker daemon -H fd:// -H tcp://0.0.0.0:4000
....
#include "docker.h"
int main(){
    Docker client = Docker("http://<ip>:<port>");

    JSON_DOCUMENT doc = client.list_containers(true); 
    std::cout << jsonToString(doc) << std::endl;

    return 0;
}

API List

System

  • system_info
  • docker_version

Image

  • list_images

Containers

  • list_containers
  • inspect_container
  • top_container
  • logs_container
  • create_container
  • start_container
  • get_container_changes
  • stop_container
  • kill_container
  • pause_container
  • wait_container
  • delete_container
  • unpause_container
  • restart_container
  • attach_to_container

About

C++ Docker Client Using HTTP API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 97.7%
  • Makefile 2.3%