-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocker.js
59 lines (51 loc) · 1.26 KB
/
docker.js
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
56
57
58
59
import Docker from 'dockerode';
const dockerode = new Docker({
socketPath: process.env.CAPTURE_DOCKER_SOCKET,
version: 'v1.37'
});
const listContainers = function() {
return new Promise(function(resolve, reject) {
dockerode.listContainers(function(err, containers) {
if (err)
reject(err);
else
resolve(containers);
});
});
};
const pull = function(image){
return new Promise( (resolve, reject) => {
dockerode.pull(image, function(err, stream) {
if(err)
reject(err);
else {
dockerode.modem.followProgress(stream, onFinished, function() {});
function onFinished(err, output) {
if(err)
reject(err);
else
resolve(output);
}
}
});
});
};
const remove = function(container) {
return new Promise( (resolve, reject) => {
container.remove(function (err, data) {
if (err)
reject(err);
else
resolve(data);
});
});
};
const docker = {
listContainers: listContainers,
pull: pull,
removeContainer: remove,
createContainer: async (obj) => dockerode.createContainer(obj),
getContainer: (id) => dockerode.getContainer(id),
getNetwork: (id, cb) => dockerode.getNetwork(id, cb)
};
export default docker;