DockerClientpp
A simple Docker SDK for C++
|
Docker client class. More...
#include <DockerClient.hpp>
Public Member Functions | |
DockerClient (DockerClient &&)=default | |
DockerClient (const SOCK_TYPE type=SOCK_UNIX, const string &path="/var/run/docker.sock") | |
Constructor, create a socket file. More... | |
void | setAPIVersion (const string &api) |
Set Docker daemon API version. More... | |
std::vector< std::string > | listImages () |
List all images. More... | |
**return Images list in json format *string | listImages () |
string | createContainer (const json &config, const string &name="") |
Create a new container based on existing image. More... | |
void | startContainer (const string &identifier) |
Start a stopped or created container. More... | |
void | stopContainer (const string &identifier) |
Stop a running container. More... | |
void | removeContainer (const string &identifier, bool remove_volume=false, bool force=false, bool remove_link=false) |
Remove a container. More... | |
string | createExecution (const string &identifier, const json &config) |
Set up an exec running instance in a running container. More... | |
string | startExecution (const string &id, const json &config={}) |
Start a execution instance that is set up previously. More... | |
string | getContainerStats (const string &id) |
Get statistics for a execution instance. More... | |
string | inspectExecution (const string &id) |
Inspect a execution instance. More... | |
void | updateContainer (const std::string &id, const json &config) |
Update the configurations of already created container. More... | |
ExecRet | executeCommand (const string &identifier, const vector< string > &cmd) |
Execute a command in a running container, like docker exec command. More... | |
void | putFiles (const string &identifier, const vector< string > &files, const string &path) |
Put files to container. More... | |
void | getFile (const string &identifier, const string &file, const string &path) |
Get file to container. More... | |
json | downloadImage (const string &imageName, const string &tag={}, const json &config={}) |
json | commitImage (const string &idOrName, const string &repo, const string &message, const string &tag={}, const json &config={}) |
Create a new image from container. More... | |
void | killContainer (const std::string &idOrName) |
int | waitContainer (const std::string &idOrName, const std::string &condition="not-running") |
string | getLogs (const string &id, bool stdoutFlag=true, bool stderrFlag=true, int tail=-1) |
string | inspectContainer (const string &id) |
string | getLongId (const std::string &name) |
std::vector< std::string > | getRunningContainers () |
Docker client class.
DockerClientpp::DockerClient::DockerClient | ( | const SOCK_TYPE | type = SOCK_UNIX , |
const string & | path = "/var/run/docker.sock" |
||
) |
Constructor, create a socket file.
type | socket type that docker daemon use |
path | path to the docker daemon socket if type is TCP, path might be a IP to docker daemon server |
json DockerClientpp::DockerClient::commitImage | ( | const string & | idOrName, |
const string & | repo, | ||
const string & | message, | ||
const string & | tag = {} , |
||
const json & | config = {} |
||
) |
Create a new image from container.
identifier | container's id or name |
description | of the commit |
tag | name for the image @config configuration parameter for creating the image |
string DockerClientpp::DockerClient::createContainer | ( | const json & | config, |
const string & | name = "" |
||
) |
Create a new container based on existing image.
This does not mean that you can pass multiple commands to Cmd. A valid command may look like this: Cmd = {"ls", "-a", "-l"}
If you want to run multiple commands in one run, consider using shell script e.g. Cmd = {"bash", "-c", "mkdir test && cd test"}
config | configuration |
name | container's name |
string DockerClientpp::DockerClient::createExecution | ( | const string & | identifier, |
const json & | config | ||
) |
Set up an exec running instance in a running container.
The execution won't start until a start command is executed on it
identifier | Container's ID or name |
config | configuration |
ExecRet DockerClientpp::DockerClient::executeCommand | ( | const string & | identifier, |
const vector< string > & | cmd | ||
) |
Execute a command in a running container, like docker exec
command.
For reference of parameters cmd see createContainer()
identifier | Container's ID or name |
cmd | Executing command with parameters in vector |
string DockerClientpp::DockerClient::getContainerStats | ( | const string & | id | ) |
Get statistics for a execution instance.
id | Execution instance ID |
void DockerClientpp::DockerClient::getFile | ( | const string & | identifier, |
const string & | file, | ||
const string & | path | ||
) |
Get file to container.
identifier | container's id or name |
file | file in the container |
path | location that the file to be stored in |
string DockerClientpp::DockerClient::inspectExecution | ( | const string & | id | ) |
Inspect a execution instance.
id | Execution instance ID |
std::vector<std::string> DockerClientpp::DockerClient::listImages | ( | ) |
List all images.
void DockerClientpp::DockerClient::putFiles | ( | const string & | identifier, |
const vector< string > & | files, | ||
const string & | path | ||
) |
Put files to container.
identifier | container's id or name |
files | files need to be put |
path | location in the container |
void DockerClientpp::DockerClient::removeContainer | ( | const string & | identifier, |
bool | remove_volume = false , |
||
bool | force = false , |
||
bool | remove_link = false |
||
) |
Remove a container.
identifier | Container's ID or name |
remove_volume | remove the mounted volume or not |
force | force to remove a container, e.g. a running container |
remove_link | remove the associated link |
void DockerClientpp::DockerClient::setAPIVersion | ( | const string & | api | ) |
Set Docker daemon API version.
The default api version is v1.24
api | api version to be set. e.g. api = "v1.24" |
void DockerClientpp::DockerClient::startContainer | ( | const string & | identifier | ) |
Start a stopped or created container.
identifier | Container's ID or name |
string DockerClientpp::DockerClient::startExecution | ( | const string & | id, |
const json & | config = {} |
||
) |
Start a execution instance that is set up previously.
The first byte of the return value indicates output type 0: stdin 1: stdout 2: stderr
id | Execution instance ID |
config | configuration |
void DockerClientpp::DockerClient::stopContainer | ( | const string & | identifier | ) |
Stop a running container.
identifier | Container's ID or name |
void DockerClientpp::DockerClient::updateContainer | ( | const std::string & | id, |
const json & | config | ||
) |
Update the configurations of already created container.
identifier | Container's ID or name |
config | configuration |