DockerClientpp
A simple Docker SDK for C++
Public Member Functions | List of all members
DockerClientpp::DockerClient Class Reference

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 ()
 

Detailed Description

Docker client class.

Constructor & Destructor Documentation

◆ DockerClient()

DockerClientpp::DockerClient::DockerClient ( const SOCK_TYPE  type = SOCK_UNIX,
const string &  path = "/var/run/docker.sock" 
)

Constructor, create a socket file.

Parameters
typesocket type that docker daemon use
pathpath to the docker daemon socket if type is TCP, path might be a IP to docker daemon server

Member Function Documentation

◆ commitImage()

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.

Parameters
identifiercontainer's id or name
descriptionof the commit
tagname for the image @config configuration parameter for creating the image

◆ createContainer()

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"}

Parameters
configconfiguration
namecontainer's name
Returns
container's id
See also
CreateContainerOption

◆ createExecution()

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

Parameters
identifierContainer's ID or name
configconfiguration
Returns
Execution ID, needed when start a execution

◆ executeCommand()

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()

Parameters
identifierContainer's ID or name
cmdExecuting command with parameters in vector
Returns
See also
createContainer()

◆ getContainerStats()

string DockerClientpp::DockerClient::getContainerStats ( const string &  id)

Get statistics for a execution instance.

Parameters
idExecution instance ID
Returns
Execution stats

◆ getFile()

void DockerClientpp::DockerClient::getFile ( const string &  identifier,
const string &  file,
const string &  path 
)

Get file to container.

Parameters
identifiercontainer's id or name
filefile in the container
pathlocation that the file to be stored in

◆ inspectExecution()

string DockerClientpp::DockerClient::inspectExecution ( const string &  id)

Inspect a execution instance.

Parameters
idExecution instance ID
Returns
Execution status

◆ listImages()

std::vector<std::string> DockerClientpp::DockerClient::listImages ( )

List all images.

Returns
Images list

◆ putFiles()

void DockerClientpp::DockerClient::putFiles ( const string &  identifier,
const vector< string > &  files,
const string &  path 
)

Put files to container.

Parameters
identifiercontainer's id or name
filesfiles need to be put
pathlocation in the container

◆ removeContainer()

void DockerClientpp::DockerClient::removeContainer ( const string &  identifier,
bool  remove_volume = false,
bool  force = false,
bool  remove_link = false 
)

Remove a container.

Parameters
identifierContainer's ID or name
remove_volumeremove the mounted volume or not
forceforce to remove a container, e.g. a running container
remove_linkremove the associated link

◆ setAPIVersion()

void DockerClientpp::DockerClient::setAPIVersion ( const string &  api)

Set Docker daemon API version.

The default api version is v1.24

Parameters
apiapi version to be set. e.g. api = "v1.24"

◆ startContainer()

void DockerClientpp::DockerClient::startContainer ( const string &  identifier)

Start a stopped or created container.

Parameters
identifierContainer's ID or name

◆ startExecution()

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

Parameters
idExecution instance ID
configconfiguration
Returns
if Detach is false, return output

◆ stopContainer()

void DockerClientpp::DockerClient::stopContainer ( const string &  identifier)

Stop a running container.

Parameters
identifierContainer's ID or name

◆ updateContainer()

void DockerClientpp::DockerClient::updateContainer ( const std::string &  id,
const json &  config 
)

Update the configurations of already created container.

Parameters
identifierContainer's ID or name
configconfiguration
Returns

The documentation for this class was generated from the following file: