-
Notifications
You must be signed in to change notification settings - Fork 3
/
dockerclient.js
49 lines (36 loc) · 878 Bytes
/
dockerclient.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
var http = require('http')
var concat = require('concat-stream')
function dockerRequest(path, done){
var options = {
socketPath: '/var/run/docker.sock',
path: path,
method: 'GET'
};
var req = http.request(options, function(res) {
res.setEncoding('utf8');
res.pipe(concat(function(body){
if(body) body = body.toString()
done(null, body, res.headers)
}))
});
req.on('error', function(e) {
done(e)
});
req.end();
}
module.exports = {
/*
return the JSON packet describing a container
this is the same as `docker inspect id`
*/
container:function(id, done){
dockerRequest('/v1.15/containers/' + id + '/json', done)
},
/*
reeturn the JSON packet describing an image
HTTP only
*/
image:function(name, done){
dockerRequest('/v1.15/images/' + name + '/json', done)
}
}