-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
dockerContainer.js
59 lines (52 loc) · 1.21 KB
/
dockerContainer.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
'use strict';
var Promise = require('bluebird');
function DockerContainer(docker, name, image, options) {
this.container = docker.createContainer(name, image, options);
}
/**
* @returns {Promise}
*/
DockerContainer.prototype.start = function () {
var self = this;
return self.container.then(function (c) {
return c.start().then(function () {
console.log('#~ Started container', c.id);
return self.waitReady();
})
})
};
/**
* @returns {Promise}
*/
DockerContainer.prototype.waitReady = function () {
return Promise.resolve(this);
}
/**
* @returns {Promise}
*/
DockerContainer.prototype.stop = function () {
return this.container.then(function (c) {
return c.stop().then(function () {
console.log('#~ Stopped container', c.id);
})
.catch(function (err) {
if (err.statusCode !== 304) {
throw err;
}
});
});
}
/**
* @returns {Promise}
*/
DockerContainer.prototype.destroy = function () {
var self = this;
return self.stop().then(function () {
return self.container.then(function (c) {
return c.remove().then(function () {
console.log('#~ Removed container', c.id);
});
});
});
}
module.exports = DockerContainer;