Docker client class.
More...
#include <DockerClient.hpp>
|
|
| DockerClient (DockerClient &&)=default |
| |
| | DockerClient (const SOCK_TYPE type=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...
|
| |
| string | listImages () |
| | List all images. More...
|
| |
| 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 | inspectExecution (const string &id) |
| | Inspect a execution instance. 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...
|
| |
§ DockerClient()
| DockerClientpp::DockerClient::DockerClient |
( |
const SOCK_TYPE |
type = UNIX, |
|
|
const string & |
path = "/var/run/docker.sock" |
|
) |
| |
Constructor, create a socket file.
- Parameters
-
| 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 |
§ 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
-
| config | configuration |
| name | container'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
-
| identifier | Container's ID or name |
| config | configuration |
- 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
-
| identifier | Container's ID or name |
| cmd | Executing command with parameters in vector |
- Returns
- See also
- createContainer()
§ getFile()
| void DockerClientpp::DockerClient::getFile |
( |
const string & |
identifier, |
|
|
const string & |
file, |
|
|
const string & |
path |
|
) |
| |
Get file to container.
- Parameters
-
| identifier | container's id or name |
| file | file in the container |
| path | location that the file to be stored in |
§ inspectExecution()
| string DockerClientpp::DockerClient::inspectExecution |
( |
const string & |
id | ) |
|
Inspect a execution instance.
- Parameters
-
- Returns
- Execution status
§ listImages()
| string DockerClientpp::DockerClient::listImages |
( |
| ) |
|
List all images.
Test Only!
- Returns
- Images list in json format
§ putFiles()
| void DockerClientpp::DockerClient::putFiles |
( |
const string & |
identifier, |
|
|
const vector< string > & |
files, |
|
|
const string & |
path |
|
) |
| |
Put files to container.
- Parameters
-
| identifier | container's id or name |
| files | files need to be put |
| path | location 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
-
| 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 |
§ setAPIVersion()
| void DockerClientpp::DockerClient::setAPIVersion |
( |
const string & |
api | ) |
|
Set Docker daemon API version.
The default api version is v1.24
- Parameters
-
| api | api version to be set. e.g. api = "v1.24" |
§ startContainer()
| void DockerClientpp::DockerClient::startContainer |
( |
const string & |
identifier | ) |
|
Start a stopped or created container.
- Parameters
-
| identifier | Container'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
-
| id | Execution instance ID |
| config | configuration |
- Returns
- if Detach is false, return output
§ stopContainer()
| void DockerClientpp::DockerClient::stopContainer |
( |
const string & |
identifier | ) |
|
Stop a running container.
- Parameters
-
| identifier | Container's ID or name |
The documentation for this class was generated from the following file: