DockerClientpp is a simple docker client sdk written in C++
This library heavily relies on Linux platform
DockerClient dc // Instantiate a client with default option: connect to /var/run/docker.sock DockerClient dc(SOCK_TYPE::SOCK_UNIX, "/path/to/docker/daemon/socket"); DockerClient dc(SOCK_TYPE::SOCK_TCP, "IP:Port"); string container_id = dc.createContainer({ {"AttachStdout", true}, {"AttachStderr", true}, {"Tty", true}, {"StopSignal", "SIGKILL"}, {"Image", "busybox:1.26"} }, "test"); ExecRet result = dc.executeCommand(container_id, {"echo", "hello DockerClientpp"}); std::cout << result.ret_code << std::endl << result.output << std::endl;Note:
- For more usage, see hello_world.cpp
- For complete API reference, see header file or documentation
- For configuration passed in docker client see Docker Engine API
git clone --recursive https://github.com/fedemengo/DockerClientpp.gitcd DockerClientppcmake .make install(with root permission)
The library's name is libDockerClientpp.a Use Headers #include <dockerclientpp/DockerClientpp.hpp> in your project
Compile the code inside the library folder
#!/bin/bash currDir=${PWD} clientDir="DockerClientpp" # cd inside the library cd ${clientDir} && \ # create build folder mkdir -p build && cd build && \ # generate make file with specific location cmake .. -DCMAKE_INSTALL_PREFIX=${PWD} && \ # install the library in the desired location make install && \ echo "Installation succeded!" Link static and dynamic libraries from source folder
CC = g++ STATIC_LIB_PATH = -LDockerClientpp/build/lib STATIC_LIB_NAME = -lDockerClientpp -larchive SHARED_LIB_PATH = -rpath=$(PWD)/DockerClientpp/build/lib INCLUDE_PATH = -IDockerClientpp/build/include/DockerClientpp LIB_FALGS = $(STATIC_LIB_PATH) $(STATIC_LIB_NAME) $(INCLUDE_PATH) -Wl,$(SHARED_LIB_PATH) -pthread all: main.cpp $(CC) main.cpp $(LIB_FALGS) clean: rm -f a.out For implementing new functionalities, see the Docker Engine API and this nice trick could be really helpful
sudo strace -e write -o strace-docker -s 10240 -f DOCKER COMMAND You can then inspect the strace-docker file and check the HTTP requests that the docker cli makes to the docker engine. Thanks to @nehaljwani for his SO answer
After cmake configuration, execute make docs. The doc files will be put under /<DockerClient root directory>/docs
- add subdirectory
- link
DOCKER_CLIENT_PP_LIBto your targets