-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhello_world.cpp
More file actions
55 lines (41 loc) · 1.42 KB
/
hello_world.cpp
File metadata and controls
55 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "dockerclientpp/DockerClientpp.hpp"
#include <fstream>
#include <iostream>
using namespace DockerClientpp;
using std::cout;
using std::endl;
int main() {
std::fstream fs("testfile", std::fstream::out);
fs << "hello world\n";
fs.close();
// Use default socket, unix domain socket: /var/run/docker.sock
DockerClient dc;
// Use tcp socket
// DockerClient dc(SOCK_TYPE::TCP, "ip:port");
string id = dc.createContainer({{"AttachStdout", true},
{"AttachStderr", true},
{"Tty", true},
{"StopSignal", "SIGKILL"},
{"Image", "busybox:1.26"}},
"test");
dc.startContainer(id);
dc.putFiles(id, {"testfile"}, "/tmp");
string exec_id =
dc.createExecution(id, {{"AttachStdout", true},
{"AttachStderr", true},
{"Tty", false},
{"Cmd", json::array({"cat", "/tmp/testfile"})}});
string output = dc.startExecution(exec_id);
cout << output;
std::remove("testfile");
dc.executeCommand(id, {"mv", "/tmp/testfile", "/tmp/test_file"});
dc.getFile(id, "/tmp/test_file", ".");
fs.open("test_file", std::fstream::in);
string s;
std::getline(fs, s);
cout << s << endl;
std::remove("test_file");
dc.stopContainer(id);
dc.removeContainer(id);
return 0;
}