-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
35 lines (32 loc) · 826 Bytes
/
index.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
var Docker = require('dockerode');
var docker = new Docker({
socketPath: '/var/run/docker.sock'
});
function gc () {
var time = ~~((Date.now() - 1000 * 60 * 10)/1000);
docker.listContainers({
all: true
}, function (err, containers) {
if (err) {
console.error(err);
} else {
containers.forEach(function (container) {
if (container.Created < time) {
console.log('removing', container.Id);
docker.getContainer(container.Id).remove({
force: true
}, function (err) {
console.log('removed', container.Id);
if (err) {
console.log(err);
}
});
} else {
console.log(container.Created, time);
}
});
}
});
}
gc();
setInterval(gc, 1000 * 60);